Cataclysm BN
item Class Reference

#include <item.h>

Inheritance diagram for item:
visitable< item >

Classes

class  craft_data
 Data for items that represent in-progress crafts. More...
 
struct  default_charges_tag
 Suppress randomization and always start with default quantity of charges. More...
 
struct  solitary_tag
 Default (or randomized) charges except if counted by charges then only one charge. More...
 
struct  sound_data
 

Public Types

using FlagsSetType = cata::flat_set< std::string >
 
using archive_type_tag = io::object_archive_tag
 

Public Member Functions

 item ()
 
 item (item &&)
 
 item (const item &)
 
itemoperator= (item &&)
 
itemoperator= (const item &)
 
 item (const itype_id &id, time_point turn=calendar::turn, int qty=-1)
 
 item (const itype *type, time_point turn=calendar::turn, int qty=-1)
 
 item (const itype_id &id, time_point turn, default_charges_tag)
 
 item (const itype *type, time_point turn, default_charges_tag)
 
 item (const itype_id &id, time_point turn, solitary_tag)
 
 item (const itype *type, time_point turn, solitary_tag)
 
 item (const recipe *rec, int qty, std::list< item > items, std::vector< item_comp > selections)
 For constructing in-progress crafts. More...
 
template<typename... Args>
 item (const std::string &itype, Args &&... args)
 
 ~item ()
 
safe_reference< itemget_safe_reference ()
 Return a pointer-like type that's automatically invalidated if this item is destroyed or assigned-to. More...
 
itemconvert (const itype_id &new_type)
 Filter converting this instance to another type preserving all other aspects. More...
 
itemdeactivate (const Character *ch=nullptr, bool alert=true)
 Filter converting this instance to the inactive type If the item is either inactive or cannot be deactivated is a no-op. More...
 
itemactivate ()
 Filter converting instance to active state. More...
 
units::energy mod_energy (const units::energy &qty)
 Add or remove energy from a battery. More...
 
itemammo_set (const itype_id &ammo, int qty=-1)
 Filter setting the ammo for this instance Any existing ammo is removed. More...
 
itemammo_unset ()
 Filter removing all ammo from this instance If the item is neither a tool, gun nor magazine is a no-op For items reloading using magazines any empty magazine remains present. More...
 
itemset_damage (int qty)
 Filter setting damage constrained by min_damage and max_damage. More...
 
item split (int qty)
 Splits a count-by-charges item always leaving source item with minimum of 1 charge. More...
 
const mtypeget_mtype () const
 
void set_mtype (const mtype *m)
 Sets the monster type associated with this item (corpse). More...
 
bool is_corpse () const
 Whether this is a corpse item. More...
 
bool can_revive () const
 Whether this is a corpse that can be revived. More...
 
bool ready_to_revive (const tripoint &pos) const
 Whether this corpse should revive now. More...
 
bool is_money () const
 
nc_color color () const
 Returns the default color of the item (e.g. More...
 
nc_color color_in_inventory () const
 Returns the color of the item depending on usefulness for the player character, e.g. More...
 
nc_color color_in_inventory (const player &p) const
 Returns the color of the item depending on usefulness for the passed player, e.g. More...
 
std::string tname (unsigned int quantity=1, bool with_prefix=true, unsigned int truncate=0) const
 Return the (translated) item name. More...
 
std::string display_money (unsigned int quantity, unsigned int total, const std::optional< unsigned int > &selected=std::nullopt) const
 
std::string display_name (unsigned int quantity=1) const
 Returns the item name and the charges or contained charges (if the item can have charges at all). More...
 
std::vector< iteminfoinfo () const
 Return all the information about the item and its type as a vector. More...
 
std::vector< iteminfoinfo (int batch) const
 
std::vector< iteminfoinfo (const iteminfo_query &parts, int batch, temperature_flag temperature) const
 
std::vector< iteminfoinfo (temperature_flag temperature) const
 
std::string info_string () const
 As info, but as a string rather than a vector of properties. More...
 
std::string info_string (const iteminfo_query &parts, int batch=1, temperature_flag temperature=temperature_flag::TEMP_NORMAL) const
 
void basic_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void med_info (const item *med_item, std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void food_info (const item *food_item, std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug, temperature_flag temperature) const
 
void magazine_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void ammo_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void gun_info (const item *mod, std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void gunmod_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void armor_protection_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void armor_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void animal_armor_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void armor_fit_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void book_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void battery_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void container_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void tool_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void component_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void repair_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void disassembly_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void qualities_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void bionic_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void combat_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void contents_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void final_info (std::vector< iteminfo > &info, const iteminfo_query &parts, int batch, bool debug) const
 
float simulate_burn (fire_data &frd) const
 Calculate all burning calculations, but don't actually apply them to item. More...
 
bool burn (fire_data &frd)
 Burns the item. More...
 
const item_categoryget_category () const
 
bool reload (player &u, item_location loc, int qty)
 Reload item using ammo from location returning true if successful. More...
 
template<typename Archive >
void io (Archive &)
 
void serialize (JsonOut &json) const
 
void deserialize (JsonIn &jsin)
 
const std::string & symbol () const
 
int price (bool practical) const
 Returns the monetary value of an item. More...
 
bool display_stacked_with (const item &rhs, bool check_components=false) const
 Whether two items should stack when displayed in a inventory menu. More...
 
bool stacks_with (const item &rhs, bool check_components=false, bool skip_type_check=false) const
 
bool merge_charges (const item &rhs)
 Merge charges of the other item into this item. More...
 
units::mass weight (bool include_contents=true, bool integral=false) const
 
units::volume volume (bool integral=false) const
 Total volume of an item accounting for all contained/integrated items NOTE: Result is rounded up to next nearest milliliter when working with stackable (count_by_charges) items that have fractional volume per charge. More...
 
units::volume base_volume () const
 Simplified, faster volume check for when processing time is important and exact volume is not. More...
 
units::volume corpse_volume (const mtype *corpse) const
 Volume check for corpses, helper for base_volume(). More...
 
int lift_strength () const
 Required strength to be able to successfully lift the item unaided by equipment. More...
 
Melee

The functions here assume the item is used in melee, even if's a gun or not a weapon at all.

Because the functions apply to all types of items, several of the is_* functions here may return true for the same item. This only indicates that it can be used in various ways.

int attack_cost () const
 Base number of moves (Creature::moves) that a single melee attack with this items takes. More...
 
int damage_melee (damage_type dt) const
 Damage of given type caused when this item is used as melee weapon. More...
 
damage_instance base_damage_melee () const
 All damage types this item deals when used in melee (no skill modifiers etc. More...
 
damage_instance base_damage_thrown () const
 All damage types this item deals when thrown (no skill modifiers etc. More...
 
double effective_dps (const player &guy, const monster &mon) const
 Calculate the item's effective damage per second past armor when wielded by a character against a monster. More...
 
std::map< std::string, double > dps (bool for_display, bool for_calc, const player &guy) const
 calculate effective dps against a stock set of monsters. More...
 
std::map< std::string, double > dps (bool for_display, bool for_calc) const
 
double average_dps (const player &guy) const
 return the average dps of the weapon against evaluation monsters More...
 
double ideal_ranged_dps (const Character &who, gun_mode &mode) const
 
bool is_two_handed (const Character &guy) const
 Whether the character needs both hands to wield this item. More...
 
bool is_melee (damage_type dt) const
 Is this item an effective melee weapon for the given damage type? More...
 
bool is_melee () const
 Is this item an effective melee weapon for any damage type? More...
 
skill_id melee_skill () const
 The most relevant skill used with this melee weapon. More...
 
int reach_range (const Character &guy) const
 Max range of melee attack this weapon can be used for. More...
 
void set_countdown (int num_turns)
 Sets time until activation for an item that will self-activate in the future. More...
 
bool use_charges (const itype_id &what, int &qty, std::list< item > &used, const tripoint &pos, const std::function< bool(const item &)> &filter=return_true< item >)
 Consumes specified charges (or fewer) from this and any contained items. More...
 
bool on_drop (const tripoint &pos)
 Invokes item type's itype::drop_action. More...
 
bool on_drop (const tripoint &pos, map &map)
 Invokes item type's itype::drop_action. More...
 
bool use_amount (const itype_id &it, int &quantity, std::list< item > &used, const std::function< bool(const item &)> &filter=return_true< item >)
 Consume a specific amount of items of a specific type. More...
 
bool allow_crafting_component () const
 Permits filthy components, should only be used as a helper in creating filters. More...
 
Containers

Containers come in two flavors:

bool is_container () const
 Whether this is container. More...
 
bool is_watertight_container () const
 Whether this is a container which can be used to store liquids. More...
 
bool is_container_empty () const
 Whether this item has no contents at all. More...
 
bool is_non_resealable_container () const
 Whether removing this item's contents will permanently alter it. More...
 
bool is_container_full (bool allow_bucket=false) const
 Whether this item has no more free capacity for its current content. More...
 
void fill_with (item &liquid, int amount=INFINITE_CHARGES)
 Fill item with liquid up to its capacity. More...
 
int get_remaining_capacity_for_liquid (const item &liquid, bool allow_bucket=false, std::string *err=nullptr) const
 How much more of this liquid (in charges) can be put in this container. More...
 
int get_remaining_capacity_for_liquid (const item &liquid, const Character &p, std::string *err=nullptr) const
 
units::volume get_container_capacity () const
 It returns the total capacity (volume) of the container for liquids. More...
 
units::volume get_total_capacity () const
 It returns the maximum volume of any contents, including liquids, ammo, magazines, weapons, etc. More...
 
void put_in (const item &payload)
 Puts the given item into this one, no checks are performed. More...
 
item in_its_container () const
 Returns this item into its default container. More...
 
item in_container (const itype_id &container_type) const
 
bool item_has_uses_recursive () const
 
bool is_funnel_container (units::volume &bigger_than) const
 Funnel related functions. More...
 
void add_rain_to_container (bool acid, int charges=1)
 Add charge(s) of rain to given container, possibly contaminating it. More...
 
int get_quality (const quality_id &id) const
 
std::map< quality_id, int > get_qualities () const
 
bool count_by_charges () const
 
int count () const
 If count_by_charges(), returns charges, otherwise 1. More...
 
bool craft_has_charges ()
 
void mod_charges (int mod)
 Modify the charges of this item, only use for items counted by charges! The item must have enough charges for this (>= quantity) and be counted by charges. More...
 
bool actualize_rot (const tripoint &pnt, temperature_flag temperature, const weather_manager &weather)
 Whether the item has to be removed as it has rotten away completely. More...
 
time_duration calc_rot (time_point time, int temp) const
 Returns rot of the item since last rot calculation. More...
 
time_duration minimum_freshness_duration (temperature_flag temperature) const
 Time that this item is guaranteed to stay fresh. More...
 
void mod_last_rot_check (time_duration processing_duration)
 This is part of a workaround so that items don't rot away to nothing if the smoking rack is outside the reality bubble. More...
 
bool process_rot (const tripoint &pos)
 Update temperature for things like food Update rot for things that perish All items that rot also have temperature. More...
 
bool process_rot (bool seals, const tripoint &pos, player *carrier, temperature_flag flag, const weather_manager &weather_generator)
 
int get_comestible_fun () const
 
bool goes_bad () const
 whether an item is perishable (can rot) More...
 
bool goes_bad_after_opening () const
 whether an item is perishable (can rot), even if it is currently in a preserving container More...
 
time_duration get_shelf_life () const
 Get the shelf life of the item. More...
 
double get_relative_rot () const
 Get rot value relative to shelf life (or 0 if item does not spoil) More...
 
void set_relative_rot (double val)
 Set current item rot relative to shelf life (no-op if item does not spoil) More...
 
void set_rot (time_duration val)
 
int spoilage_sort_order () const
 Get time left to rot, ignoring fridge. More...
 
bool is_fresh () const
 an item is fresh if it is capable of rotting but still has a long shelf life remaining More...
 
bool is_going_bad () const
 an item is about to become rotten when shelf life has nearly elapsed More...
 
bool rotten () const
 returns true if item is now rotten after all shelf life has elapsed More...
 
bool has_rotten_away () const
 Whether the item has enough rot that it should get removed. More...
 
time_duration get_rot () const
 
void mod_rot (const time_duration &val)
 
time_duration brewing_time () const
 Time for this item to be fully fermented. More...
 
const std::vector< itype_id > & brewing_results () const
 The results of fermenting this item. More...
 
bool detonate (const tripoint &p, std::vector< item > &drops)
 Detonates the item and adds remains (if any) to drops. More...
 
bool will_explode_in_fire () const
 
Material(s) of the item

Each item is made of one or more materials (material_type).

Materials have properties that affect properties of the item (e.g. resistance against certain damage types).

Corpses inherit the material of the monster type.

const material_typeget_random_material () const
 Get a material reference to a random material that this item is made of. More...
 
const material_typeget_base_material () const
 Get the basic (main) material of this item. More...
 
const std::vector< material_id > & made_of () const
 The ids of all the materials this is made of. More...
 
const std::map< quality_id, int > & quality_of () const
 The ids of all the qualities this contains. More...
 
std::vector< const material_type * > made_of_types () const
 Same as made_of(), but returns the material_type directly. More...
 
bool made_of_any (const std::set< material_id > &mat_idents) const
 Check we are made of at least one of a set (e.g. More...
 
bool only_made_of (const std::set< material_id > &mat_idents) const
 Check we are made of only the materials (e.g. More...
 
bool made_of (const material_id &mat_ident) const
 Check we are made of this material (e.g. More...
 
bool contents_made_of (phase_id phase) const
 If contents nonempty, return true if item phase is same, else false. More...
 
bool made_of (phase_id phase) const
 Are we solid, liquid, gas, plasma? More...
 
std::vector< item_compget_uncraft_components () const
 Returns a list of components used to craft this item or the default components if it wasn't player-crafted. More...
 
bool conductive () const
 Whether the items is conductive. More...
 
bool flammable (int threshold=0) const
 Whether the items is flammable. More...
 
bool reinforceable () const
 Whether the item can be repaired beyond normal health. More...
 
int acid_resist (bool to_self=false, int base_env_resist=0) const
 Resistance against different damage types (damage_type). More...
 
int fire_resist (bool to_self=false, int base_env_resist=0) const
 
int bash_resist (bool to_self=false) const
 
int cut_resist (bool to_self=false) const
 
int stab_resist (bool to_self=false) const
 
int bullet_resist (bool to_self=false) const
 
void mitigate_damage (damage_unit &du) const
 Assuming that specified du hit the armor, reduce du based on the item's resistance to the damage type. More...
 
int damage_resist (damage_type dt, bool to_self=false) const
 Resistance provided by this item against damage type given by an enum. More...
 
int chip_resistance (bool worst=false) const
 Returns resistance to being damaged by attack against the item itself. More...
 
int damage () const
 How much damage has the item sustained? More...
 
int damage_level (int max) const
 Scale item damage to the given number of levels. More...
 
int min_damage () const
 Minimum amount of damage to an item (state of maximum repair) More...
 
int max_damage () const
 Maximum amount of damage to an item (state before destroyed) More...
 
float get_relative_health () const
 Relative item health. More...
 
bool mod_damage (int qty, damage_type dt)
 Apply damage to const itemrained by min_damage and max_damage. More...
 
bool mod_damage (int qty)
 same as other mod_damage, but uses DT_NULL as damage type. More...
 
bool inc_damage (damage_type dt)
 Increment item damage by itype::damage_scale constrained by max_damage. More...
 
bool inc_damage ()
 same as other inc_damage, but uses DT_NULL as damage type. More...
 
nc_color damage_color () const
 Provide color for UI display dependent upon current item damage level. More...
 
std::string damage_symbol () const
 Provide prefix symbol for UI display dependent upon current item damage level. More...
 
std::string durability_indicator (bool include_intact=false) const
 Provides a prefix for the durability state of the item. More...
 
const std::set< itype_id > & repaired_with () const
 If possible to repair this item what tools could potentially be used for this purpose? More...
 
bool already_used_by_player (const player &p) const
 Check whether the item has been marked (by calling mark_as_used_by_player) as used by this specific player. More...
 
void mark_as_used_by_player (const player &p)
 Marks the item as being used by this specific player, it remains unmarked for other players. More...
 
bool is_filthy () const
 Marks the item as filthy, so characters with squeamish trait can't wear it. More...
 
bool process (player *carrier, const tripoint &pos, bool activate, temperature_flag flag=temperature_flag::TEMP_NORMAL)
 This is called once each turn. More...
 
bool process (player *carrier, const tripoint &pos, bool activate, temperature_flag flag, const weather_manager &weather_generator)
 
std::optional< tripointget_cable_target (Character *p, const tripoint &pos) const
 Gets the point (vehicle tile) the cable is connected to. More...
 
void reset_cable (player *p)
 Helper to bring a cable back to its initial state. More...
 
bool needs_processing () const
 Whether the item should be processed (by calling process). More...
 
int processing_speed () const
 The rate at which an item should be processed, in number of turns between updates. More...
 
void process_artifact (player *carrier, const tripoint &pos)
 Process and apply artifact effects. More...
 
void process_relic (Character &carrier)
 
bool destroyed_at_zero_charges () const
 
bool is_null () const
 
bool is_comestible () const
 
bool is_food () const
 
bool is_food_container () const
 
bool is_med_container () const
 
bool is_ammo_container () const
 
bool is_medication () const
 
bool is_bionic () const
 
bool is_magazine () const
 
bool is_battery () const
 
bool is_ammo_belt () const
 
bool is_bandolier () const
 
bool is_holster () const
 
bool is_ammo () const
 
bool is_pet_armor (bool on_pet=false) const
 
bool is_armor () const
 
bool is_book () const
 
bool is_map () const
 
bool is_salvageable () const
 
bool is_craft () const
 
bool is_deployable () const
 
bool is_tool () const
 
bool is_transformable () const
 
bool is_artifact () const
 
bool is_relic () const
 
bool is_bucket () const
 
bool is_bucket_nonempty () const
 
bool is_brewable () const
 
bool is_engine () const
 
bool is_wheel () const
 
bool is_fuel () const
 
bool is_toolmod () const
 
bool is_faulty () const
 
bool is_irremovable () const
 
bool is_unarmed_weapon () const
 
itemget_food ()
 
const itemget_food () const
 
int wind_resist () const
 How resistant clothes made of this material are to wind (0-100) More...
 
std::set< fault_idfaults_potential () const
 What faults can potentially occur with this item? More...
 
int wheel_area () const
 Returns the total area of this wheel or 0 if it isn't one. More...
 
float fuel_energy () const
 Returns energy of one charge of this item as fuel for an engine. More...
 
std::string fuel_pump_terrain () const
 Returns the string of the id of the terrain that pumps this fuel, if any. More...
 
bool has_explosion_data () const
 
struct fuel_explosion get_explosion_data ()
 
bool can_contain (const item &it) const
 Can this item have given item/itype as content? More...
 
bool can_contain (const itype &tp) const
 
bool is_reloadable () const
 Is it ever possible to reload this item? Only the base item is considered with any mods ignored. More...
 
bool can_reload_with (const ammotype &ammo) const
 Returns true if this item can be reloaded with specified ammo type, ignoring currently loaded ammo. More...
 
bool can_reload_with (const itype_id &ammo) const
 Returns true if this item can be reloaded with specified ammo item, ignoring currently loaded ammo. More...
 
bool is_reloadable_with (const itype_id &ammo) const
 Returns true if this item can be reloaded with specified ammo type at this moment. More...
 
bool can_unload_liquid () const
 Returns true if not empty if it's liquid, it's not currently frozen in resealable container. More...
 
bool is_dangerous () const
 
bool is_tainted () const
 Is item derived from a zombie? More...
 
bool is_soft () const
 Is this item flexible enough to be worn on body parts like antlers? More...
 
bool has_effect_when_wielded (art_effect_passive effect) const
 Does the item provide the artifact effect when it is wielded? More...
 
bool has_effect_when_worn (art_effect_passive effect) const
 Does the item provide the artifact effect when it is worn? More...
 
bool has_effect_when_carried (art_effect_passive effect) const
 Does the item provide the artifact effect when it is carried? More...
 
void set_snippet (const snippet_id &id)
 Set the snippet text (description) of this specific item, using the snippet library. More...
 
bool operator< (const item &other) const
 
bool operator== (const item &rhs) const
 LUA: We need this operator defined for Lua bindings to compile. More...
 
bool operator<= (const item &other) const
 LUA: We need this operator defined for Lua bindings to compile. More...
 
std::string components_to_string () const
 List of all components in printable form, empty if this item has no components. More...
 
uint64_t make_component_hash () const
 Creates a hash from the itype_ids of this item's components. More...
 
const itype_idtypeId () const
 return the unique identifier of the items underlying type More...
 
const itemget_contained () const
 Return a contained item (if any and only one). More...
 
bool spill_contents (Character &c)
 Unloads the item's contents. More...
 
bool spill_contents (const tripoint &pos)
 Unloads the item's contents. More...
 
bool can_holster (const item &obj, bool ignore=false) const
 Checks if item is a holster and currently capable of storing obj. More...
 
void on_wear (Character &p)
 Callback when a character starts wearing the item. More...
 
void on_takeoff (Character &p)
 Callback when a character takes off an item. More...
 
void on_wield (player &p, int mv=0)
 Callback when a player starts wielding the item. More...
 
void on_pickup (Character &p)
 Callback when a player starts carrying the item. More...
 
void on_contents_changed ()
 Callback when contents of the item are affected in any way other than just processing. More...
 
void on_damage (int qty, damage_type dt)
 Callback immediately before an item is damaged. More...
 
std::vector< trait_idmutations_from_wearing (const Character &guy) const
 
std::string type_name (unsigned int quantity=1) const
 Name of the item type (not the item), with proper plural. More...
 
int charges_per_volume (const units::volume &vol) const
 Number of (charges of) this item that fit into the given volume. More...
 
Item variables

Item variables can be used to store any value in the item.

The storage is persistent, it remains through saving & loading, it is copied when the item is moved etc. Each item variable is referred to by its name, so make sure you use a name that is not already used somewhere. You can directly store integer, floating point and string values. Data of other types must be converted to one of those to be stored. The set_var functions override the existing value. The get_var function return the value (if the variable exists), or the default value otherwise. The type of the default value determines which get_var function is used. All numeric values are returned as doubles and may be cast to the desired type. int v = itm.get_var("v", 0); // v will be an int double d = itm.get_var("v", 0.0); // d will be a double std::string s = itm.get_var("v", ""); // s will be a std::string // no default means empty string as default: auto n = itm.get_var("v"); // v will be a std::string

void set_var (const std::string &name, int value)
 
void set_var (const std::string &name, long long value)
 
void set_var (const std::string &name, long value)
 
void set_var (const std::string &name, double value)
 
double get_var (const std::string &name, double default_value) const
 
void set_var (const std::string &name, const tripoint &value)
 
tripoint get_var (const std::string &name, const tripoint &default_value) const
 
void set_var (const std::string &name, const std::string &value)
 
std::string get_var (const std::string &name, const std::string &default_value) const
 
std::string get_var (const std::string &name) const
 Get the variable, if it does not exists, returns an empty string. More...
 
bool has_var (const std::string &name) const
 Whether the variable is defined at all. More...
 
void erase_var (const std::string &name)
 Erase the value of the given variable. More...
 
void clear_vars ()
 Removes all item variables. More...
 
Item flags

If you use any new flags, add them to flags.json, add a comment to doc/JSON_FLAGS.md and make sure your new flag does not conflict with any existing flag.

Item flags are taken from the item type (itype::item_tags), but also from the item itself (item_tags). The item has the flag if it appears in either set.

Gun mods that are attached to guns also contribute their flags to the gun item.

bool has_flag (const std::string &flag) const
 
bool has_flag (const flag_str_id &flag) const
 
template<typename Container , typename T = std::decay_t<decltype( *std::declval<const Container &>().begin() )>>
bool has_any_flag (const Container &flags) const
 
bool has_own_flag (const std::string &flag) const
 Checks whether item itself has given flag (doesn't check item type or gunmods). More...
 
const FlagsSetTypeget_flags () const
 returs read-only set of flags of this item (not including flags from item type or gunmods) More...
 
itemset_flag (const std::string &flag)
 Idempotent filter setting an item specific flag. More...
 
itemunset_flag (const std::string &flag)
 Idempotent filter removing an item specific flag. More...
 
itemset_flag_recursive (const std::string &flag)
 Idempotent filter recursively setting an item specific flag on this item and its components. More...
 
void unset_flags ()
 Removes all item specific flags. More...
 
bool has_fault (const fault_id &fault) const
 Does this item have the specified fault. More...
 
Item properties

Properties are specific to an item type so unlike flags the meaning of a property may not be the same for two different item types.

Each item type can have multiple properties however duplicate property names are not permitted.

bool has_property (const std::string &prop) const
 
std::string get_property_string (const std::string &prop, const std::string &def="") const
 Get typed property for item. More...
 
int64_t get_property_int64_t (const std::string &prop, int64_t def=0) const
 
Light emitting items

Items can emit light either through the definition of their type (itype::light_emission) or through an item specific light data (light).

bool getlight (float &luminance, units::angle &width, units::angle &direction) const
 Directional light emission of the item. More...
 
int getlight_emit () const
 How much light (see lightmap.cpp) the item emits (it's assumed to be circular). More...
 
bool is_emissive () const
 Whether the item emits any light at all. More...
 
Seed data.
bool is_seed () const
 Whether this is actually a seed, the seed functions won't be of much use for non-seeds. More...
 
time_duration get_plant_epoch () const
 Time it takes to grow from one stage to another. More...
 
std::string get_plant_name () const
 The name of the plant as it appears in the various informational menus. More...
 
Armor related functions.

The functions here refer to values from islot_armor.

They only apply to armor items, those items can be worn. The functions are safe to call for any item, for non-armor they return a default value.

bool covers (body_part bp) const
 Whether this item (when worn) covers the given body part. More...
 
bool covers (const bodypart_id &bp) const
 
body_part_set get_covered_body_parts () const
 Bitset of all covered body parts. More...
 
body_part_set get_covered_body_parts (side s) const
 Bitset of all covered body parts, from a specific side. More...
 
bool is_sided () const
 Returns true if item is armor and can be worn on different sides of the body. More...
 
side get_side () const
 Returns side item currently worn on. More...
 
bool set_side (side s)
 Change the side on which the item is worn. More...
 
bool swap_side ()
 Swap the side on which the item is worn. More...
 
int get_warmth () const
 Returns the warmth value that this item has when worn. More...
 
int get_thickness () const
 Returns the islot_armor::thickness value, or 0 for non-armor. More...
 
layer_level get_layer () const
 Returns clothing layer for item. More...
 
int get_coverage () const
 Returns the relative coverage that this item has when worn. More...
 
int get_encumber_when_containing (const Character &, const units::volume &contents_volume) const
 Returns the encumbrance value that this item has when worn by given player, when containing a particular volume of contents. More...
 
int get_encumber (const Character &) const
 Returns the encumbrance value that this item has when worn by given player. More...
 
units::volume get_storage () const
 Returns the storage amount (islot_armor::storage) that this item provides when worn. More...
 
float get_weight_capacity_modifier () const
 Returns the weight capacity modifier (islot_armor::weight_capacity_modifier) that this item provides when worn. More...
 
units::mass get_weight_capacity_bonus () const
 Returns the weight capacity bonus (islot_armor::weight_capacity_modifier) that this item provides when worn. More...
 
int get_env_resist (int override_base_resist=0) const
 Returns the resistance to environmental effects (islot_armor::env_resist) that this item provides when worn. More...
 
int get_base_env_resist_w_filter () const
 Returns the base resistance to environmental effects if an item (for example a gas mask) requires a gas filter to operate and this filter is installed. More...
 
bool is_power_armor () const
 Whether this is a power armor item. More...
 
const islot_armorfind_armor_data () const
 If this is an armor item, return its armor data. More...
 
bool is_worn_only_with (const item &it) const
 Returns true whether this item can be worn only when. More...
 
Pet armor related functions.

The functions here refer to values from islot_pet_armor.

They only apply to pet armor items, those items can be worn by pets. The functions are safe to call for any item, for non-pet armor they return a default value.

units::volume get_pet_armor_max_vol () const
 
units::volume get_pet_armor_min_vol () const
 
bodytype_id get_pet_armor_bodytype () const
 
Books

Book specific functions, apply to items that are books.

int get_chapters () const
 How many chapters the book has (if any). More...
 
int get_remaining_chapters (const Character &ch) const
 Get the number of unread chapters. More...
 
void mark_chapter_as_read (const Character &ch)
 Mark one chapter of the book as read by the given player. More...
 
std::vector< std::pair< const recipe *, int > > get_available_recipes (const player &u) const
 Enumerates recipes available from this book and the skill level required to use them. More...
 
Martial art techniques

See martialarts.h for further info.

bool has_technique (const matec_id &tech) const
 Whether the item supports a specific martial art technique (either through its type, or through its individual techniques). More...
 
std::set< matec_idget_techniques () const
 Returns all the martial art techniques that this items supports. More...
 
void add_technique (const matec_id &tech)
 Add the given technique to the item specific techniques. More...
 
std::vector< item * > toolmods ()
 Returns all toolmods currently attached to this item (always empty if item not a tool) More...
 
std::vector< const item * > toolmods () const
 
Gun and gunmod functions

Gun and gun mod functions.

Anything stated to apply to guns, applies to auxiliary gunmods as well (they are some kind of gun). Non-guns are items that are neither gun nor auxiliary gunmod.

bool is_gunmod () const
 
bool is_gun () const
 Can this item be used to perform a ranged attack? More...
 
units::energy energy_remaining () const
 Quantity of energy currently loaded in tool or battery. More...
 
int ammo_remaining () const
 Quantity of ammunition currently loaded in tool, gun or auxiliary gunmod. More...
 
int ammo_capacity () const
 Maximum quantity of ammunition loadable for tool, gun or auxiliary gunmod. More...
 
int ammo_capacity (bool potential_capacity) const
 
int ammo_required () const
 Quantity of ammunition consumed per usage of tool or with each shot of gun. More...
 
bool ammo_sufficient (int qty=1) const
 Check if sufficient ammo is loaded for given number of uses. More...
 
int ammo_consume (int qty, const tripoint &pos)
 Consume ammo (if available) and return the amount of ammo that was consumed. More...
 
const itypeammo_data () const
 Specific ammo data, returns nullptr if item is neither ammo nor loaded with any. More...
 
itype_id ammo_current () const
 Specific ammo type, returns "null" if item is neither ammo nor loaded with any. More...
 
const std::set< ammotype > & ammo_types (bool conversion=true) const
 Set of ammo types (ammunition_type) used by item. More...
 
ammotype ammo_type () const
 Ammo type of an ammo item. More...
 
itype_id ammo_default (bool conversion=true) const
 Get default ammo used by item or a null id if item does not have a default ammo type. More...
 
itype_id common_ammo_default (bool conversion=true) const
 Get default ammo for the first ammotype common to an item and its current magazine or "NULL" if none exists. More...
 
std::set< ammo_effect_str_idammo_effects (bool with_ammo=true) const
 Get ammo effects for item optionally inclusive of any resulting from the loaded ammo. More...
 
std::string ammo_sort_name () const
 
int casings_count () const
 How many spent casings are contained within this item? More...
 
void casings_handle (const std::function< bool(item &)> &func)
 Apply predicate to each contained spent casing removing it if predicate returns true. More...
 
bool magazine_integral () const
 Does item have an integral magazine (as opposed to allowing detachable magazines) More...
 
itype_id magazine_default (bool conversion=true) const
 Get the default magazine type (if any) for the current effective ammo type. More...
 
std::set< itype_idmagazine_compatible (bool conversion=true) const
 Get compatible magazines (if any) for this item. More...
 
itemmagazine_current ()
 Currently loaded magazine (if any) More...
 
const itemmagazine_current () const
 
std::vector< item * > gunmods ()
 Returns all gunmods currently attached to this item (always empty if item not a gun) More...
 
std::vector< const item * > gunmods () const
 
itemgunmod_find (const itype_id &mod)
 Get first attached gunmod matching type or nullptr if no such mod or item is not a gun. More...
 
const itemgunmod_find (const itype_id &mod) const
 
ret_val< bool > is_gunmod_compatible (const item &mod) const
 
std::map< gun_mode_id, gun_modegun_all_modes () const
 Get all possible modes for this gun inclusive of any attached gunmods. More...
 
gun_mode gun_get_mode (const gun_mode_id &mode) const
 Check if gun supports a specific mode returning an invalid/empty mode if not. More...
 
gun_mode gun_current_mode () const
 Get the current mode for this gun (or an invalid mode if item is not a gun) More...
 
gun_mode_id gun_get_mode_id () const
 Get id of mode a gun is currently set to, e.g. More...
 
bool gun_set_mode (const gun_mode_id &mode)
 Try to set the mode for a gun, returning false if no such mode is possible. More...
 
void gun_cycle_mode ()
 Switch to the next available firing mode. More...
 
int sight_dispersion () const
 Get lowest dispersion of either integral or any attached sights. More...
 
sound_data gun_noise (bool burst=false) const
 Returns the sound of the gun being fired. More...
 
bool is_silent () const
 Whether this is a (nearly) silent gun (a tiny bit of sound is allowed). More...
 
int gun_range (const player *p) const
 The weapons range in map squares. More...
 
int gun_range (bool with_ammo=true) const
 Summed range value of a gun, including values from mods. More...
 
double gun_recoil_multiplier (bool bipod=false) const
 Get multiplier on recoil considering handling and attached gunmods. More...
 
int gun_recoil (bool bipod=false) const
 Get effective recoil considering handling, loaded ammo and effects of attached gunmods. More...
 
damage_instance gun_damage (bool with_ammo=true) const
 Summed ranged damage, armor piercing, and multipliers for both, of a gun, including values from mods. More...
 
int gun_dispersion (bool with_ammo=true, bool with_scaling=true) const
 Summed dispersion of a gun, including values from mods. More...
 
skill_id gun_skill () const
 The skill used to operate the gun. More...
 
std::map< gunmod_location, int > get_mod_locations () const
 Get mod locations, including those added by other mods. More...
 
int get_free_mod_locations (const gunmod_location &location) const
 Number of mods that can still be installed into the given mod location, for non-guns it always returns 0. More...
 
bool is_firearm () const
 Does it require gunsmithing tools to repair. More...
 
int get_reload_time () const
 Returns the reload time of the gun. More...
 
Vehicle parts
int engine_displacement () const
 for combustion engines the displacement (cc) More...
 
- Public Member Functions inherited from visitable< item >
VisitResponse visit_items (const std::function< VisitResponse(item *, item *)> &func)
 Traverses this object and any child items contained using a visitor pattern. More...
 
VisitResponse visit_items (const std::function< VisitResponse(const item *, const item *)> &func) const
 
VisitResponse visit_items (const std::function< VisitResponse(item *)> &func)
 Lightweight version which provides only the current node. More...
 
VisitResponse visit_items (const std::function< VisitResponse(const item *)> &func) const
 
itemfind_parent (const item &it)
 Determine the immediate parent container (if any) for an item. More...
 
const itemfind_parent (const item &it) const
 
std::vector< item * > parents (const item &it)
 Returns vector of parent containers (if any) starting with the innermost. More...
 
std::vector< const item * > parents (const item &it) const
 
bool has_item (const item &it) const
 Returns true if this visitable instance contains the item. More...
 
bool has_item_with (const std::function< bool(const item &)> &filter) const
 Returns true if any item (including those within a container) matches the filter. More...
 
bool has_quality (const quality_id &qual, int level=1, int qty=1) const
 Returns true if instance has amount (or more) items of at least quality level. More...
 
int max_quality (const quality_id &qual) const
 Return maximum tool quality level provided by instance or INT_MIN if not found. More...
 
int charges_of (const itype_id &what, int limit=INT_MAX, const std::function< bool(const item &)> &filter=return_true< item >, std::function< void(int)> visitor=nullptr) const
 Count maximum available charges from this instance and any contained items. More...
 
int amount_of (const itype_id &what, bool pseudo=true, int limit=INT_MAX, const std::function< bool(const item &)> &filter=return_true< item >) const
 Count items matching id including both this instance and any contained items. More...
 
bool has_amount (const itype_id &what, int qty, bool pseudo=true, const std::function< bool(const item &)> &filter=return_true< item >) const
 Check instance provides at least qty of an item (. More...
 
std::vector< item * > items_with (const std::function< bool(const item &)> &filter)
 Returns all items (including those within a container) matching the filter. More...
 
std::vector< const item * > items_with (const std::function< bool(const item &)> &filter) const
 
std::list< itemremove_items_with (const std::function< bool(const item &)> &filter, int count=INT_MAX)
 Removes items contained by this instance which match the filter. More...
 
item remove_item (item &it)
 Removes and returns the item which must be contained by this instance. More...
 

Static Public Member Functions

static item make_corpse (const mtype_id &mt=string_id< mtype >::NULL_ID(), time_point turn=calendar::turn, const std::string &name="", int upgrade_time=-1)
 Make a corpse of the given monster type. More...
 

Bionics / CBMs

Functions specific to CBMs

enum class  sizing {
  human_sized_human_char = 0 , big_sized_human_char , small_sized_human_char , big_sized_big_char ,
  human_sized_big_char , small_sized_big_char , small_sized_small_char , human_sized_small_char ,
  big_sized_small_char , not_wearable
}
 
static const int INFINITE_CHARGES = INT_MAX
 
const itypetype
 
item_contents contents
 
std::list< itemcomponents
 
std::set< fault_idfaults
 What faults (if any) currently apply to this item. More...
 
FlagsSetType item_tags
 
int charges
 
units::energy energy
 
int recipe_charges = 1
 
int burnt = 0
 
int poison = 0
 
int frequency = 0
 
snippet_id snip_id = snippet_id::NULL_ID()
 
int irradiation = 0
 
int item_counter = 0
 
int mission_id = -1
 
int player_id = -1
 
bool encumbrance_update_ = false
 
char invlet = 0
 
bool active = false
 
safe_reference< Characteractivated_by
 
bool is_favorite = false
 
pimpl< item_drop_tokendrop_token
 Two items are dropped in same "batch" if they have identical drop tokens Ideally, this would be stored outside item class. More...
 
safe_reference_anchor anchor
 
const itypecurammo = nullptr
 
std::map< std::string, std::string > item_vars
 
const mtypecorpse = nullptr
 
std::string corpse_name
 
std::set< matec_idtechniques
 
cata::value_ptr< craft_datacraft_data_
 
cata::value_ptr< relicrelic_data
 
time_duration rot = 0_turns
 Accumulated rot, expressed as time the item has been in standard temperature. More...
 
time_point last_rot_check = calendar::turn_zero
 Time when the rot calculation was last performed. More...
 
time_point bday
 The time the item was created. More...
 
faction_id owner = faction_id::NULL_ID()
 
faction_id old_owner = faction_id::NULL_ID()
 
int damage_ = 0
 
light_emission light = nolight
 
bool is_upgrade () const
 Whether the CBM is an upgrade to another bionic module. More...
 
bool has_use () const
 Returns true if the item has any use function. More...
 
const use_functionget_use (const std::string &use_name) const
 Returns the pointer to use_function with name use_name assigned to the type of this item or any of its contents. More...
 
itemget_usable_item (const std::string &use_name)
 Checks this item and its contents (recursively) for types that have use_function with type use_name. More...
 
int units_remaining (const Character &ch, int limit=INT_MAX) const
 How many units (ammo or charges) are remaining? More...
 
bool units_sufficient (const Character &ch, int qty=-1) const
 Check if item has sufficient units (ammo or charges) remaining. More...
 
std::string get_corpse_name ()
 Returns name of deceased being if it had any or empty string if not. More...
 
bool has_label () const
 Returns true if item has "item_label" itemvar. More...
 
std::string label (unsigned int quantity=0) const
 Returns label from "item_label" itemvar and quantity. More...
 
bool has_infinite_charges () const
 
skill_id contextualize_skill (const skill_id &id) const
 Puts the skill in context of the item. More...
 
bool release_monster (const tripoint &target, int radius=0)
 
int contain_monster (const tripoint &target)
 
time_duration age () const
 
void set_age (const time_duration &age)
 
void legacy_fast_forward_time ()
 
time_point birthday () const
 
void set_birthday (const time_point &bday)
 
void handle_pickup_ownership (Character &c)
 
int get_gun_ups_drain () const
 
void validate_ownership () const
 
void set_old_owner (const faction_id &temp_owner)
 
void remove_old_owner () const
 
void set_owner (const faction_id &new_owner)
 
void set_owner (const Character &c)
 
void remove_owner () const
 
faction_id get_owner () const
 
faction_id get_old_owner () const
 
bool is_owned_by (const Character &c, bool available_to_take=false) const
 
bool is_old_owner (const Character &c, bool available_to_take=false) const
 
std::string get_owner_name () const
 
int get_min_str () const
 
const cata::value_ptr< islot_comestible > & get_comestible () const
 
const recipeget_making () const
 Get the stored recipe for in progress crafts. More...
 
int get_next_failure_point () const
 Get the failure point stored in this item. More...
 
void set_next_failure_point (const player &crafter)
 Calculates and sets the next failure point for an in progress craft. More...
 
bool handle_craft_failure (player &crafter)
 Handle failure during crafting. More...
 
requirement_data get_continue_reqs () const
 Returns requirement data representing what is needed to resume work on an in progress craft. More...
 
void inherit_flags (const item &parent, const recipe &making)
 Inherit applicable flags from the given parent item. More...
 
void inherit_flags (const std::list< item > &parents, const recipe &making)
 Inherit applicable flags from the given list of parent items. More...
 
void set_tools_to_continue (bool value)
 
bool has_tools_to_continue () const
 
void set_cached_tool_selections (const std::vector< comp_selection< tool_comp > > &selections)
 
const std::vector< comp_selection< tool_comp > > & get_cached_tool_selections () const
 
const std::vector< enchantment > & get_enchantments () const
 
double bonus_from_enchantments (const Character &owner, double base, enchant_vals::mod value, bool round=false) const
 Calculate bonus from enchantments that affect this item only. More...
 
double bonus_from_enchantments_wielded (double base, enchant_vals::mod value, bool round=false) const
 Calculate bonus from enchantments that affect this item only, assume it's wielded and all enchantments' conditions are satisfied. More...
 
const std::vector< relic_recharge > & get_relic_recharge_scheme () const
 
sizing get_sizing (const Character &, bool) const
 
void set_favorite (bool favorite)
 
bool has_clothing_mod () const
 
float get_clothing_mod_val (clothing_mod_type type) const
 
void update_clothing_mod_val ()
 
static std::string nname (const itype_id &id, unsigned int quantity=1)
 Returns the translated item name for the item with given id. More...
 
static bool count_by_charges (const itype_id &id)
 Whether the item is counted by charges, this is a static wrapper around count_by_charges, that does not need an items instance. More...
 
bool use_amount_internal (const itype_id &it, int &quantity, std::list< item > &used, const std::function< bool(const item &)> &filter=return_true< item >)
 
const use_functionget_use_internal (const std::string &use_name) const
 
bool process_internal (player *carrier, const tripoint &pos, bool activate, bool seals, temperature_flag flag, const weather_manager &weather_generator)
 
bool is_reloadable_helper (const itype_id &ammo, bool now) const
 Helper for checking reloadability. More...
 
bool process_corpse (player *carrier, const tripoint &pos)
 
bool process_wet (player *carrier, const tripoint &pos)
 
bool process_litcig (player *carrier, const tripoint &pos)
 
bool process_extinguish (player *carrier, const tripoint &pos)
 
bool process_fake_smoke (player *carrier, const tripoint &pos)
 
bool process_fake_mill (player *carrier, const tripoint &pos)
 
bool process_cable (player *carrier, const tripoint &pos)
 
bool process_UPS (player *carrier, const tripoint &pos)
 
bool process_blackpowder_fouling (player *carrier)
 
bool process_tool (player *carrier, const tripoint &pos)
 

Additional Inherited Members

Detailed Description

Definition at line 209 of file item.h.

Member Typedef Documentation

◆ archive_type_tag

Definition at line 493 of file item.h.

◆ FlagsSetType

using item::FlagsSetType = cata::flat_set<std::string>

Definition at line 212 of file item.h.

Member Enumeration Documentation

◆ sizing

enum class item::sizing
strong
Enumerator
human_sized_human_char 
big_sized_human_char 
small_sized_human_char 
big_sized_big_char 
human_sized_big_char 
small_sized_big_char 
small_sized_small_char 
human_sized_small_char 
big_sized_small_char 
not_wearable 

Definition at line 2136 of file item.h.

2136 {
2137 human_sized_human_char = 0,
2138 big_sized_human_char,
2139 small_sized_human_char,
2140 big_sized_big_char,
2141 human_sized_big_char,
2142 small_sized_big_char,
2143 small_sized_small_char,
2144 human_sized_small_char,
2145 big_sized_small_char,
2146 not_wearable
2147 };

Constructor & Destructor Documentation

◆ item() [1/11]

item::item ( )

Definition at line 369 of file item.cpp.

370{
371 type = nullitem();
372 charges = 0;
373}
time_point bday
The time the item was created.
Definition: item.h:2237
int charges
Definition: item.h:2209
const itype * type
Definition: item.h:2170
static const itype * nullitem()
Definition: item.cpp:320
const time_point & start_of_cataclysm
Definition: calendar.cpp:33

References charges, nullitem(), and type.

Referenced by add_rain_to_container(), ammo_set(), vehicle_part::deserialize(), io(), item(), and split().

◆ item() [2/11]

item::item ( item &&  )
default

◆ item() [3/11]

item::item ( const item )
default

◆ item() [4/11]

item::item ( const itype_id id,
time_point  turn = calendar::turn,
int  qty = -1 
)
explicit

Definition at line 435 of file item.cpp.

436 : item( & * id, turn, qty ) {}
item()
Definition: item.cpp:369
time_point turn
Definition: calendar.cpp:36

◆ item() [5/11]

item::item ( const itype type,
time_point  turn = calendar::turn,
int  qty = -1 
)
explicit

Definition at line 375 of file item.cpp.

375 : type( type ), bday( turn )
376{
377 corpse = has_flag( flag_CORPSE ) ? &mtype_id::NULL_ID().obj() : nullptr;
379
380 if( qty >= 0 ) {
381 charges = qty;
382 } else {
383 if( type->tool && type->tool->rand_charges.size() > 1 ) {
384 const int charge_roll = rng( 1, type->tool->rand_charges.size() - 1 );
385 charges = rng( type->tool->rand_charges[charge_roll - 1], type->tool->rand_charges[charge_roll] );
386 } else {
388 }
389 }
390
392 itype_id nanofab_recipe = item_group::item_from( item_group_id( "nanofab_recipes" ) ).typeId();
393 set_var( "NANOFAB_ITEM_ID", nanofab_recipe.str() );
394 }
395
396 if( type->gun ) {
397 for( const itype_id &mod : type->gun->built_in_mods ) {
398 item it( mod, turn, qty );
399 it.set_flag( "IRREMOVABLE" );
400 put_in( it );
401 }
402 for( const itype_id &mod : type->gun->default_mods ) {
403 put_in( item( mod, turn, qty ) );
404 }
405
406 } else if( type->magazine ) {
407 if( type->magazine->count > 0 ) {
408 put_in( item( type->magazine->default_ammo, calendar::turn, type->magazine->count ) );
409 }
410
411 } else if( goes_bad() ) {
412 active = true;
414
415 } else if( type->tool ) {
416 if( ammo_remaining() && !ammo_types().empty() ) {
418 }
419 }
420
421 if( ( type->gun || type->tool ) && !magazine_integral() ) {
422 set_var( "magazine_converted", 1 );
423 }
424
425 if( !type->snippet_category.empty() ) {
427 }
428
429 // item always has any relic properties from itype.
430 if( type->relic_data ) {
432 }
433}
units::quantity< V, B > rng(const units::quantity< V, B > &min, const units::quantity< V, B > &max)
Definition: artifact.cpp:32
Definition: item.h:210
int ammo_remaining() const
Quantity of ammunition currently loaded in tool, gun or auxiliary gunmod.
Definition: item.cpp:7400
bool active
Definition: item.h:2247
void put_in(const item &payload)
Puts the given item into this one, no checks are performed.
Definition: item.cpp:999
void set_var(const std::string &name, int value)
Definition: item.cpp:1004
item & ammo_set(const itype_id &ammo, int qty=-1)
Filter setting the ammo for this instance Any existing ammo is removed.
Definition: item.cpp:594
bool goes_bad() const
whether an item is perishable (can rot)
Definition: item.cpp:5524
const mtype * corpse
Definition: item.h:2182
snippet_id snip_id
Definition: item.h:2216
const itype_id & typeId() const
return the unique identifier of the items underlying type
Definition: item.cpp:8375
bool magazine_integral() const
Does item have an integral magazine (as opposed to allowing detachable magazines)
Definition: item.cpp:7678
bool has_flag(const std::string &flag) const
Definition: item.cpp:5329
itype_id ammo_default(bool conversion=true) const
Get default ammo used by item or a null id if item does not have a default ammo type.
Definition: item.cpp:7614
time_point last_rot_check
Time when the rot calculation was last performed.
Definition: item.h:2235
const std::set< ammotype > & ammo_types(bool conversion=true) const
Set of ammo types (ammunition_type) used by item.
Definition: item.cpp:7583
int item_counter
Definition: item.h:2218
cata::value_ptr< relic > relic_data
Definition: item.h:2207
snippet_id random_id_from_category(const std::string &cat) const
Returns the id of a random snippet out of the given category.
const T & obj() const
Returns the actual object this id refers to.
Definition: achievement.cpp:63
const std::string & str() const
Returns the identifier as plain std::string.
Definition: string_id.h:263
static const string_id< mtype > & NULL_ID()
Returns a null id whose string_id<T>::is_null() must always return true.
static const std::string flag_NANOFAB_TEMPLATE("NANOFAB_TEMPLATE")
static const std::string flag_CORPSE("CORPSE")
item item_from(const item_group_id &group_id, const time_point &birthday)
Returns a random item from the item group, handles packaged food by putting it into its container and...
Definition: item_group.cpp:589
std::string snippet_category
Definition: itype.h:878
cata::value_ptr< islot_gun > gun
Definition: itype.h:830
cata::value_ptr< islot_tool > tool
Definition: itype.h:820
int charges_default() const
Definition: itype.cpp:98
cata::value_ptr< relic > relic_data
Definition: itype.h:838
cata::value_ptr< islot_magazine > magazine
Definition: itype.h:832
int countdown_interval
Default countdown interval (if any) for item.
Definition: itype.h:924
snippet_library SNIPPET
string_id< Item_group > item_group_id
Definition: type_id.h:77

References active, ammo_default(), ammo_remaining(), ammo_set(), ammo_types(), bday, charges, itype::charges_default(), corpse, itype::countdown_interval, flag_CORPSE(), flag_NANOFAB_TEMPLATE(), goes_bad(), itype::gun, has_flag(), item(), item_counter, item_group::item_from(), last_rot_check, itype::magazine, magazine_integral(), string_id< mtype >::NULL_ID(), string_id< T >::obj(), put_in(), snippet_library::random_id_from_category(), relic_data, itype::relic_data, rng(), set_flag(), set_var(), snip_id, SNIPPET, itype::snippet_category, string_id< T >::str(), itype::tool, calendar::turn, type, and typeId().

◆ item() [6/11]

item::item ( const itype_id id,
time_point  turn,
default_charges_tag  tag 
)

Definition at line 441 of file item.cpp.

442 : item( & * id, turn, tag ) {}

◆ item() [7/11]

item::item ( const itype type,
time_point  turn,
default_charges_tag   
)

Definition at line 438 of file item.cpp.

439 : item( type, turn, type->charges_default() ) {}

◆ item() [8/11]

item::item ( const itype_id id,
time_point  turn,
solitary_tag  tag 
)

Definition at line 447 of file item.cpp.

448 : item( & * id, turn, tag ) {}

◆ item() [9/11]

item::item ( const itype type,
time_point  turn,
solitary_tag   
)

Definition at line 444 of file item.cpp.

445 : item( type, turn, type->count_by_charges() ? 1 : -1 ) {}
bool count_by_charges() const
Definition: itype.cpp:93

◆ item() [10/11]

item::item ( const recipe rec,
int  qty,
std::list< item items,
std::vector< item_comp selections 
)

For constructing in-progress crafts.

Definition at line 468 of file item.cpp.

469 : item( "craft", calendar::turn, qty )
470{
471 craft_data_ = cata::make_value<craft_data>();
472 craft_data_->making = rec;
473 components = items;
474 craft_data_->comps_used = selections;
475
476 if( is_food() ) {
477 active = true;
479 if( goes_bad() ) {
480 const item *most_rotten = get_most_rotten_component( *this );
481 if( most_rotten ) {
482 set_relative_rot( most_rotten->get_relative_rot() );
483 }
484 }
485 }
486
487 for( item &component : components ) {
488 for( const std::string &f : component.item_tags ) {
489 if( json_flag::get( f ).craft_inherit() ) {
490 set_flag( f );
491 }
492 }
493 for( const std::string &f : component.type->get_flags() ) {
494 if( json_flag::get( f ).craft_inherit() ) {
495 set_flag( f );
496 }
497 }
498 }
499 // this extra section is so that in-progress crafts will correctly display expected flags.
500 for( const std::string &flag : rec->flags_to_delete ) {
501 unset_flag( flag );
502 }
503}
cata::value_ptr< craft_data > craft_data_
Definition: item.h:2204
std::list< item > components
Definition: item.h:2172
bool is_food() const
Definition: item.cpp:6618
item & set_flag(const std::string &flag)
Idempotent filter setting an item specific flag.
Definition: item.cpp:5358
item & unset_flag(const std::string &flag)
Idempotent filter removing an item specific flag.
Definition: item.cpp:5364
void set_relative_rot(double val)
Set current item rot relative to shelf life (no-op if item does not spoil)
Definition: item.cpp:5565
double get_relative_rot() const
Get rot value relative to shelf life (or 0 if item does not spoil)
Definition: item.cpp:5557
static const json_flag & get(const std::string &id)
Fetches flag definition (or null flag if not found)
Definition: flag.cpp:70
std::set< std::string > flags_to_delete
Definition: recipe.h:115
static const item * get_most_rotten_component(const item &craft)
Definition: item.cpp:455
itype_id type
Definition: requirements.h:58
const FlagsSetType & get_flags() const
Definition: itype.cpp:156

References active, bday, components, craft_data_, recipe::flags_to_delete, json_flag::get(), itype::get_flags(), get_most_rotten_component(), get_relative_rot(), goes_bad(), is_food(), last_rot_check, set_flag(), set_relative_rot(), component::type, and unset_flag().

◆ item() [11/11]

template<typename... Args>
item::item ( const std::string &  itype,
Args &&...  args 
)
inline

Definition at line 240 of file item.h.

240 :
241 item( itype_id( itype ), std::forward<Args>( args )... )
242 {}
Definition: itype.h:805

◆ ~item()

item::~item ( )
default

Member Function Documentation

◆ acid_resist()

int item::acid_resist ( bool  to_self = false,
int  base_env_resist = 0 
) const

Resistance against different damage types (damage_type).

Larger values means more resistance are thereby better, but there is no absolute value to compare them to. The values can be interpreted as chance (one_in) of damaging the item when exposed to the type of damage.

Parameters
to_selfIf this is true, it returns item's own resistance, not one it gives to wearer.
base_env_resistWill override the base environmental resistance (to allow hypothetical calculations for gas masks).

Definition at line 6153 of file item.cpp.

6154{
6155 if( to_self ) {
6156 // Currently no items are damaged by acid
6157 return INT_MAX;
6158 }
6159
6160 float resist = 0.0;
6162 if( is_null() ) {
6163 return 0.0;
6164 }
6165
6166 const std::vector<const material_type *> mat_types = made_of_types();
6167 if( !mat_types.empty() ) {
6168 // Not sure why cut and bash get an armor thickness bonus but acid doesn't,
6169 // but such is the way of the code.
6170
6171 for( const material_type *mat : mat_types ) {
6172 resist += mat->acid_resist();
6173 }
6174 // Average based on number of materials.
6175 resist /= mat_types.size();
6176 }
6177
6178 const int env = get_env_resist( base_env_resist );
6179 if( env < 10 ) {
6180 // Low env protection means it doesn't prevent acid seeping in.
6181 resist *= env / 10.0f;
6182 }
6183
6184 return std::lround( resist + mod );
6185}
float get_clothing_mod_val(clothing_mod_type type) const
Definition: item.cpp:10190
bool is_null() const
Definition: item.cpp:736
std::vector< const material_type * > made_of_types() const
Same as made_of(), but returns the material_type directly.
Definition: item.cpp:6452
int get_env_resist(int override_base_resist=0) const
Returns the resistance to environmental effects (islot_armor::env_resist) that this item provides whe...
Definition: item.cpp:5789
@ clothing_mod_type_acid
Definition: clothing_mod.h:17

References clothing_mod_type_acid, get_clothing_mod_val(), get_env_resist(), is_null(), and made_of_types().

Referenced by armor_inventory_preset::armor_inventory_preset(), armor_protection_info(), anonymous_namespace{armor_layers.cpp}::clothing_protection(), damage_resist(), and sew_advanced_actor::use().

◆ activate()

item & item::activate ( )

Filter converting instance to active state.

Definition at line 561 of file item.cpp.

562{
563 if( active ) {
564 return *this; // no-op
565 }
566
567 if( type->countdown_interval > 0 ) {
569 }
570
571 active = true;
572
573 return *this;
574}

References active, itype::countdown_interval, item_counter, and type.

Referenced by iuse::cable_attach(), make_gun_projectile(), process(), and process_internal().

◆ actualize_rot()

bool item::actualize_rot ( const tripoint pnt,
temperature_flag  temperature,
const weather_manager weather 
)

Whether the item has to be removed as it has rotten away completely.

May change the item as it calls process_rot()

Parameters
pntThe position of the item on the current map.
temperatureFlag for special locations that affect temperature.
weatherWeather manager to supply temperature.
Returns
true if the item has rotten away and should be removed, false otherwise.

Definition at line 8821 of file item.cpp.

8823{
8824 if( goes_bad() ) {
8825 return process_rot( false, pnt, nullptr, temperature, weather );
8826 } else if( type->container && type->container->preserves ) {
8827 // Containers like tin cans preserves all items inside, they do not rot at all.
8828 return false;
8829 } else if( type->container && type->container->seals ) {
8830 // Items inside rot but do not vanish as the container seals them in.
8831 for( item *c : contents.all_items_top() ) {
8832 if( c->goes_bad() ) {
8833 c->process_rot( true, pnt, nullptr, temperature, weather );
8834 }
8835 }
8836 return false;
8837 } else {
8838 std::vector<item *> removed_items;
8839 // Check and remove rotten contents, but always keep the container.
8840 for( item *it : contents.all_items_top() ) {
8841 if( it->actualize_rot( pnt, temperature, weather ) ) {
8842 removed_items.push_back( it );
8843 }
8844 }
8845 for( item *it : removed_items ) {
8846 remove_item( *it );
8847 }
8848
8849 return false;
8850 }
8851}
std::list< item * > all_items_top()
returns a list of pointers to all top-level items
item_contents contents
Definition: item.h:2171
bool process_rot(const tripoint &pos)
Update temperature for things like food Update rot for things that perish All items that rot also hav...
Definition: item.cpp:8968
item remove_item(item &it)
Removes and returns the item which must be contained by this instance.
Definition: visitable.cpp:565
constexpr double c
Definition: magic.cpp:1032
quantity< int, temperature_in_millidegree_celsius_tag > temperature
cata::value_ptr< islot_container > container
Slots for various item type properties.
Definition: itype.h:819

References item_contents::all_items_top(), c, itype::container, contents, goes_bad(), process_rot(), visitable< item >::remove_item(), and type.

◆ add_technique()

void item::add_technique ( const matec_id tech)

Add the given technique to the item specific techniques.

Note that other items of the same type are not affected by this.

Definition at line 5470 of file item.cpp.

5471{
5472 techniques.insert( tech );
5473}
std::set< matec_id > techniques
Definition: item.h:2184

References techniques.

Referenced by mdeath::jabberwock().

◆ age()

◆ allow_crafting_component()

bool item::allow_crafting_component ( ) const

Permits filthy components, should only be used as a helper in creating filters.

Definition at line 8555 of file item.cpp.

8556{
8557 if( is_toolmod() && is_irremovable() ) {
8558 return false;
8559 }
8560
8561 // vehicle batteries are implemented as magazines of charge
8562 if( is_magazine() && ammo_types().count( ammo_battery ) ) {
8563 return true;
8564 }
8565
8566 // fixes #18886 - turret installation may require items with irremovable mods
8567 if( is_gun() ) {
8568 bool valid = true;
8569 visit_items( [&]( const item * it ) {
8570 if( this == it ) {
8571 return VisitResponse::NEXT;
8572 }
8573 if( !( it->is_magazine() || ( it->is_gunmod() && it->is_irremovable() ) ) ) {
8574 valid = false;
8575 return VisitResponse::ABORT;
8576 }
8577 return VisitResponse::NEXT;
8578 } );
8579 return valid;
8580 }
8581
8582 return contents.empty();
8583}
bool empty() const
int count() const
If count_by_charges(), returns charges, otherwise 1.
Definition: item.cpp:6036
bool is_irremovable() const
Definition: item.cpp:6801
bool is_gun() const
Can this item be used to perform a ranged attack?
Definition: item.cpp:6543
bool is_toolmod() const
Definition: item.cpp:6791
bool is_gunmod() const
Definition: item.cpp:6573
bool is_magazine() const
Definition: item.cpp:6583
VisitResponse visit_items(const std::function< VisitResponse(item *, item *)> &func)
Traverses this object and any child items contained using a visitor pattern.
Definition: visitable.cpp:423
static const ammotype ammo_battery("battery")

References ammo_battery, ammo_types(), contents, count(), item_contents::empty(), is_gun(), is_gunmod(), is_irremovable(), is_magazine(), is_toolmod(), NEXT, and visitable< item >::visit_items().

◆ already_used_by_player()

bool item::already_used_by_player ( const player p) const

Check whether the item has been marked (by calling mark_as_used_by_player) as used by this specific player.

Definition at line 8870 of file item.cpp.

8871{
8872 const auto it = item_vars.find( USED_BY_IDS );
8873 if( it == item_vars.end() ) {
8874 return false;
8875 }
8876 // USED_BY_IDS always starts *and* ends with a ';', the search string
8877 // ';<id>;' matches at most one part of USED_BY_IDS, and only when exactly that
8878 // id has been added.
8879 const std::string needle = string_format( ";%d;", p.getID().get_value() );
8880 return it->second.find( needle ) != std::string::npos;
8881}
character_id getID() const
Definition: character.cpp:495
int get_value() const
Definition: character_id.h:23
std::map< std::string, std::string > item_vars
Definition: item.h:2181
static const std::string USED_BY_IDS("USED_BY_IDS")
std::string string_format(std::string_view format, Args &&...args)
Simple wrapper over string_formatter::parse.

References character_id::get_value(), Character::getID(), item_vars, string_format(), and USED_BY_IDS().

Referenced by tname(), and reveal_map_actor::use().

◆ ammo_capacity() [1/2]

◆ ammo_capacity() [2/2]

int item::ammo_capacity ( bool  potential_capacity) const
Parameters
potential_capacitywhether to try a default magazine if necessary

Definition at line 7432 of file item.cpp.

7433{
7434 int res = 0;
7435
7436 const item *mag = magazine_current();
7437 if( mag ) {
7438 return mag->ammo_capacity();
7439 }
7440
7441 if( is_tool() ) {
7442 res = type->tool->max_charges;
7443 if( res == 0 && magazine_default() && potential_capacity ) {
7444 res = magazine_default()->magazine->capacity;
7445 }
7446 for( const item *e : toolmods() ) {
7447 res *= e->type->mod->capacity_multiplier;
7448 }
7449 }
7450
7451 if( is_gun() ) {
7452 res = type->gun->clip;
7453 for( const item *e : gunmods() ) {
7454 res *= e->type->mod->capacity_multiplier;
7455 }
7456 }
7457
7458 if( is_magazine() ) {
7459 res = type->magazine->capacity;
7460 }
7461
7462 if( is_bandolier() ) {
7463 return dynamic_cast<const bandolier_actor *>
7464 ( type->get_use( "bandolier" )->get_actor_ptr() )->capacity;
7465 }
7466
7467 return res;
7468}
Store ammo and later reload using it.
Definition: iuse_actor.h:884
std::vector< item * > toolmods()
Returns all toolmods currently attached to this item (always empty if item not a tool)
Definition: item.cpp:5475
bool is_tool() const
Definition: item.cpp:6984
itype_id magazine_default(bool conversion=true) const
Get the default magazine type (if any) for the current effective ammo type.
Definition: item.cpp:7693
bool is_bandolier() const
Definition: item.cpp:6598
item * magazine_current()
Currently loaded magazine (if any)
Definition: item.cpp:7740
std::vector< item * > gunmods()
Returns all gunmods currently attached to this item (always empty if item not a gun)
Definition: item.cpp:7753
const use_function * get_use(const std::string &iuse_name) const
Definition: itype.cpp:166
iuse_actor * get_actor_ptr()
Definition: iuse.h:316

References ammo_capacity(), use_function::get_actor_ptr(), itype::get_use(), itype::gun, gunmods(), is_bandolier(), is_gun(), is_magazine(), is_tool(), itype::magazine, magazine_current(), magazine_default(), itype::tool, toolmods(), and type.

◆ ammo_consume()

int item::ammo_consume ( int  qty,
const tripoint pos 
)

Consume ammo (if available) and return the amount of ammo that was consumed.

Parameters
qtymaximum amount of ammo that should be consumed
poscurrent location of item, used for ejecting magazines and similar effects
Returns
amount of ammo consumed which will be between 0 and qty

Definition at line 7498 of file item.cpp.

7499{
7500 if( qty < 0 ) {
7501 debugmsg( "Cannot consume negative quantity of ammo for %s", tname() );
7502 return 0;
7503 }
7504
7505 item *mag = magazine_current();
7506 if( mag ) {
7507 const int res = mag->ammo_consume( qty, pos );
7508 if( res && ammo_remaining() == 0 ) {
7509 if( mag->has_flag( flag_MAG_DESTROY ) ) {
7510 remove_item( *mag );
7511 } else if( mag->has_flag( flag_MAG_EJECT ) ) {
7512 get_map().add_item( pos, *mag );
7513 remove_item( *mag );
7514 }
7515 }
7516 return res;
7517 }
7518
7519 if( is_magazine() ) {
7520 int need = qty;
7521 while( !contents.empty() ) {
7522 item &e = contents.front();
7523 if( need >= e.charges ) {
7524 need -= e.charges;
7526 } else {
7527 e.charges -= need;
7528 need = 0;
7529 break;
7530 }
7531 }
7532 return qty - need;
7533
7534 } else if( is_tool() || is_gun() ) {
7535 qty = std::min( qty, charges );
7537 avatar &you = get_avatar();
7540 }
7541 charges -= qty;
7542 if( charges == 0 ) {
7543 curammo = nullptr;
7544 }
7545 return qty;
7546 }
7547
7548 return 0;
7549}
avatar & get_avatar()
Definition: avatar.cpp:105
void mod_power_level(const units::energy &npower)
Definition: character.cpp:1925
units::energy get_power_level() const
Definition: character.cpp:1905
Definition: avatar.h:55
item & front()
this is an artifact of the previous code using front() everywhere for contents.
std::string tname(unsigned int quantity=1, bool with_prefix=true, unsigned int truncate=0) const
Return the (translated) item name.
Definition: item.cpp:4575
int ammo_consume(int qty, const tripoint &pos)
Consume ammo (if available) and return the amount of ammo that was consumed.
Definition: item.cpp:7498
const itype * curammo
Definition: item.h:2180
item & add_item(const tripoint &p, item new_item)
Place an item on the map, despite the parameter name, this is not necessarily a new item.
Definition: map.cpp:4455
#define debugmsg(...)
Debug message of level DL::Error and class DC::DebugMsg, also includes the source file name and line,...
Definition: debug.h:75
static const std::string flag_USES_BIONIC_POWER("USES_BIONIC_POWER")
static const std::string flag_MAG_DESTROY("MAG_DESTROY")
static const std::string flag_MAG_EJECT("MAG_EJECT")
map & get_map()
Definition: map.cpp:148
constexpr value_type to_kilojoule(const quantity< value_type, energy_in_joule_tag > &v)
Definition: units_energy.h:46
constexpr quantity< value_type, energy_in_joule_tag > from_kilojoule(const value_type v)
Definition: units_energy.h:32

References map::add_item(), ammo_consume(), ammo_remaining(), charges, contents, curammo, debugmsg, item_contents::empty(), flag_MAG_DESTROY(), flag_MAG_EJECT(), flag_USES_BIONIC_POWER(), units::from_kilojoule(), item_contents::front(), get_avatar(), get_map(), Character::get_power_level(), has_flag(), is_gun(), is_magazine(), is_tool(), magazine_current(), Character::mod_power_level(), visitable< item >::remove_item(), tname(), and units::to_kilojoule().

Referenced by ammo_consume(), vehicle_part::ammo_consume(), Character::consume_charges(), iuse::einktabletpc(), ranged::fire_gun(), activity_handlers::game_do_turn(), iuse::gasmask(), iuse::multicooker(), iuse::note_bionics(), activity_handlers::oxytorch_do_turn(), npc::pretend_fire(), process_tool(), reload(), activity_handlers::repair_item_finish(), toolweapon_on(), and activity_handlers::vibe_do_turn().

◆ ammo_current()

itype_id item::ammo_current ( ) const

Specific ammo type, returns "null" if item is neither ammo nor loaded with any.

Definition at line 7577 of file item.cpp.

7578{
7579 const itype *ammo = ammo_data();
7580 return ammo ? ammo->get_id() : itype_id::NULL_ID();
7581}
const itype * ammo_data() const
Specific ammo data, returns nullptr if item is neither ammo nor loaded with any.
Definition: item.cpp:7551
const itype_id & get_id() const
Definition: itype.cpp:88

References ammo_data(), itype::get_id(), and string_id< itype >::NULL_ID().

Referenced by vehicle_part::ammo_current(), turret_data::ammo_options(), npc::confident_gun_mode_range(), display_name(), aim_activity_actor::do_turn(), avatar_action::fire_wielded_weapon(), get_remaining_capacity_for_liquid(), ranged::get_shape_factory(), gun_noise(), npc_ai::gun_value(), ideal_ranged_dps(), is_reloadable_helper(), make_gun_projectile(), parse_tags(), remove_ammo(), activity_handlers::repair_item_finish(), stacks_with(), avatar_funcs::unload_item(), iuse_transform::use(), and weight().

◆ ammo_data()

const itype * item::ammo_data ( ) const

Specific ammo data, returns nullptr if item is neither ammo nor loaded with any.

Definition at line 7551 of file item.cpp.

7552{
7553 const item *mag = magazine_current();
7554 if( mag ) {
7555 return mag->ammo_data();
7556 }
7557
7558 if( is_ammo() ) {
7559 return type;
7560 }
7561
7562 if( is_magazine() ) {
7563 return !contents.empty() ? contents.front().ammo_data() : nullptr;
7564 }
7565
7566 auto mods = is_gun() ? gunmods() : toolmods();
7567 for( const item *e : mods ) {
7568 if( !e->type->mod->ammo_modifier.empty() && e->ammo_current() &&
7569 e->ammo_current().is_valid() ) {
7570 return &*e->ammo_current();
7571 }
7572 }
7573
7574 return curammo;
7575}
bool is_ammo() const
Definition: item.cpp:6608

References ammo_data(), contents, curammo, item_contents::empty(), item_contents::front(), gunmods(), is_ammo(), is_gun(), is_magazine(), magazine_current(), toolmods(), and type.

Referenced by ammo_current(), ammo_data(), turret_data::ammo_data(), ammo_effects(), ammo_info(), cycle_action(), Character::deactivate_bionic(), avatar_action::fire_wielded_weapon(), gun_damage(), gun_dispersion(), gun_info(), gun_noise(), gun_range(), gun_recoil(), ranged::handle_gun_damage(), is_reloadable_helper(), make_gun_projectile(), Item_modifier::modify(), price(), character_funcs::select_ammo(), target_ui::update_ammo_range_from_gun_mode(), weapon_inventory_preset::weapon_inventory_preset(), and weight().

◆ ammo_default()

itype_id item::ammo_default ( bool  conversion = true) const

Get default ammo used by item or a null id if item does not have a default ammo type.

Parameters
conversionwhether to include the effect of any flags or mods which convert the type
Returns
itype_id::NULL_ID() if item does not use a specific ammo type (and is consequently not reloadable)

Definition at line 7614 of file item.cpp.

7615{
7616 if( is_magazine() ) {
7617 return type->magazine->default_ammo;
7618 }
7619
7620 const std::set<ammotype> &atypes = ammo_types( conversion );
7621 if( !atypes.empty() ) {
7622 itype_id res = ammotype( *atypes.begin() )->default_ammotype();
7623 if( !res.is_empty() ) {
7624 return res;
7625 }
7626 }
7627 return itype_id::NULL_ID();
7628}
const itype_id & default_ammotype() const
Definition: ammo.h:21
bool is_empty() const
Returns whether this id is empty.
Definition: string_id.h:306
string_id< ammunition_type > ammotype
Definition: type_id.h:12

References ammo_types(), ammunition_type::default_ammotype(), string_id< T >::is_empty(), is_magazine(), itype::magazine, string_id< itype >::NULL_ID(), and type.

Referenced by basecamp::add_resource(), turret_data::ammo_current(), crafting::complete_disassemble(), game::dump_stats(), npc::enough_time_to_reload(), inventory::form_from_map(), gun_info(), npc_ai::gun_value(), ideal_ranged_dps(), item(), Item_modifier::modify(), relic_funcs::process_recharge_entry(), gun_actor::shoot(), starting_inv(), iexamine::use_furn_fake_item(), npc_ai::wielded_value(), and debug_menu::wishitem().

◆ ammo_effects()

std::set< ammo_effect_str_id > item::ammo_effects ( bool  with_ammo = true) const

Get ammo effects for item optionally inclusive of any resulting from the loaded ammo.

Definition at line 7646 of file item.cpp.

7647{
7648 if( !is_gun() ) {
7649 return std::set<ammo_effect_str_id>();
7650 }
7651
7652 std::set<ammo_effect_str_id> res = type->gun->ammo_effects;
7653 if( with_ammo && ammo_data() ) {
7654 res.insert( ammo_data()->ammo->ammo_effects.begin(), ammo_data()->ammo->ammo_effects.end() );
7655 }
7656
7657 for( const item *mod : gunmods() ) {
7658 res.insert( mod->type->gunmod->ammo_effects.begin(), mod->type->gunmod->ammo_effects.end() );
7659 }
7660
7661 return res;
7662}

References ammo_data(), itype::gun, gunmods(), is_gun(), and type.

Referenced by turret_data::ammo_effects(), gun_noise(), ranged::handle_gun_damage(), and make_gun_projectile().

◆ ammo_info()

void item::ammo_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 1908 of file item.cpp.

1910{
1911 if( is_gun() || !ammo_data() || !parts->test( iteminfo_parts::AMMO_REMAINING_OR_TYPES ) ) {
1912 return;
1913 }
1914
1915 const std::string space = " ";
1916 if( ammo_remaining() > 0 ) {
1917 info.emplace_back( "AMMO", _( "<bold>Ammunition</bold>: " ),
1918 ammo_data()->nname( ammo_remaining() ) );
1919 } else if( is_ammo() ) {
1920 info.emplace_back( "AMMO", _( "<bold>Ammunition type</bold>: " ), ammo_type()->name() );
1921 }
1922
1923 const islot_ammo &ammo = *ammo_data()->ammo;
1924 if( !ammo.damage.empty() || ammo.force_stat_display ) {
1925 bool has_flat_dmg = !ammo.damage.empty() && ammo.damage.damage_units.front().amount > 0;
1926 bool display_flat_dmg = parts->test( iteminfo_parts::AMMO_DAMAGE_VALUE );
1927 // TODO: Multiple units
1928 bool has_dmg_multiplier = ammo.damage.damage_units.front().damage_multiplier != 1.0;
1929 bool display_dmg_multiplier = parts->test( iteminfo_parts::AMMO_DAMAGE_PROPORTIONAL );
1930 bool didnt_print_dmg = false;
1931 if( has_flat_dmg && has_dmg_multiplier
1932 && has_dmg_multiplier && display_dmg_multiplier ) {
1933 info.emplace_back( "AMMO", _( "Damage: " ), "",
1935 info.emplace_back( "AMMO", "/", "",
1937 ammo.damage.damage_units.front().damage_multiplier );
1938 // Messy ifs...
1939 } else if( display_dmg_multiplier && ( has_dmg_multiplier || !has_flat_dmg ) ) {
1940 info.emplace_back( "AMMO", _( "Damage multiplier: " ), "",
1942 ammo.damage.damage_units.front().damage_multiplier );
1943 } else if( display_flat_dmg ) {
1944 info.emplace_back( "AMMO", _( "Damage: " ), "",
1946 } else {
1947 didnt_print_dmg = true;
1948 }
1949
1950 // Ugly, but handles edge cases better than mandatory space
1951 static const std::string no_space;
1952 const std::string &maybe_space = didnt_print_dmg ? no_space : space;
1953
1954 // TODO: Deduplicate with damage display
1955 bool has_flat_arpen = get_ranged_pierce( ammo ) != 0;
1956 bool display_flat_arpen = parts->test( iteminfo_parts::AMMO_DAMAGE_AP );
1957 bool has_armor_mult = get_ranged_armor_mult( ammo ) != 1.0;
1958 bool display_armor_mult = parts->test( iteminfo_parts::AMMO_DAMAGE_AP_PROPORTIONAL );
1959 if( has_flat_arpen && display_flat_arpen
1960 && has_armor_mult && display_armor_mult ) {
1961 info.emplace_back( "AMMO", maybe_space + _( "Armor-pierce: " ), "",
1963 info.emplace_back( "AMMO", "/", "",
1965 get_ranged_armor_mult( ammo ) );
1966 } else if( has_armor_mult && display_armor_mult ) {
1967 info.emplace_back( "AMMO", maybe_space + _( "Armor multiplier: " ), "",
1969 } else if( display_flat_arpen ) {
1970 info.emplace_back( "AMMO", maybe_space + _( "Armor-pierce: " ), get_ranged_pierce( ammo ) );
1971 }
1972 if( parts->test( iteminfo_parts::AMMO_DAMAGE_RANGE ) ) {
1973 info.emplace_back( "AMMO", _( "Range: " ), "", iteminfo::no_newline, ammo.shape
1974 ? static_cast<int>( ammo.shape->get_range() )
1975 : ammo.range );
1976 }
1978 info.emplace_back( "AMMO", space + _( "Dispersion: " ), "",
1980 }
1982 info.emplace_back( "AMMO", _( "Recoil: " ), "",
1984 }
1985 }
1986
1987 // TODO: De-hardcode. Have it imply a flag? Just include description_on_item in ammo_effect struct?
1988 std::vector<std::string> fx;
1989 if( ammo.shape &&
1990 parts->test( iteminfo_parts::AMMO_SHAPE ) ) {
1991 fx.emplace_back( string_format(
1992 _( "This ammo will produce effects with the following shape:\n<bold>%s</bold>" ),
1993 ammo.shape->get_description() ) );
1994 }
1995 if( ammo.ammo_effects.count( ammo_effect_RECYCLED ) &&
1997 fx.emplace_back( _( "This ammo has been <bad>hand-loaded</bad>." ) );
1998 }
1999 if( ammo.ammo_effects.count( ammo_effect_BLACKPOWDER ) &&
2001 fx.emplace_back(
2002 _( "This ammo has been loaded with <bad>blackpowder</bad>, and will quickly "
2003 "clog up most guns, and cause rust if the gun is not cleaned." ) );
2004 }
2005 if( ammo.ammo_effects.count( ammo_effect_NEVER_MISFIRES ) &&
2007 fx.emplace_back( _( "This ammo <good>never misfires</good>." ) );
2008 }
2009 if( ammo.ammo_effects.count( ammo_effect_INCENDIARY ) &&
2011 fx.emplace_back( _( "This ammo <neutral>starts fires</neutral>." ) );
2012 }
2013 if( !fx.empty() ) {
2015 for( const std::string &e : fx ) {
2016 info.emplace_back( "AMMO", e );
2017 }
2018 }
2019}
static std::string nname(const itype_id &id, unsigned int quantity=1)
Returns the translated item name for the item with given id.
Definition: item.cpp:9952
std::vector< iteminfo > info() const
Return all the information about the item and its type as a vector.
Definition: item.cpp:3992
ammotype ammo_type() const
Ammo type of an ammo item.
Definition: item.cpp:7606
bool test(const iteminfo_parts &value) const
static const ammo_effect_str_id ammo_effect_NEVER_MISFIRES("NEVER_MISFIRES")
static float get_ranged_armor_mult(const common_ranged_data &ranged)
Definition: item.cpp:1104
static const ammo_effect_str_id ammo_effect_INCENDIARY("INCENDIARY")
static const ammo_effect_str_id ammo_effect_BLACKPOWDER("BLACKPOWDER")
static void insert_separation_line(std::vector< iteminfo > &info)
Definition: item.cpp:1305
static int get_ranged_pierce(const common_ranged_data &ranged)
Definition: item.cpp:1095
static const ammo_effect_str_id ammo_effect_RECYCLED("RECYCLED")
@ AMMO_DAMAGE_AP_PROPORTIONAL
std::string name(type dir)
Get Human readable name of a direction.
Definition: overmap.cpp:4140
int dispersion
Dispersion "bonus" from gun.
Definition: itype.h:421
damage_instance damage
Damage, armor piercing and multipliers for each.
Definition: itype.h:413
int range
Range bonus from gun.
Definition: itype.h:417
std::vector< damage_unit > damage_units
Definition: damage.h:52
float total_damage() const
Definition: damage.cpp:75
bool empty() const
Definition: damage.cpp:88
std::optional< bool > force_stat_display
Some combat ammo might not have a damage value Set this to make it show as combat ammo anyway.
Definition: itype.h:702
std::optional< shape_factory > shape
AoE shape or null if it's a projectile.
Definition: itype.h:707
int recoil
Recoil (per shot), roughly equivalent to kinetic energy (in Joules)
Definition: itype.h:682
std::set< ammo_effect_str_id > ammo_effects
See ammo_effect struct.
Definition: itype.h:674
@ no_newline
Do not follow with a newline.
Definition: item.h:146
@ is_decimal
Print as decimal rather than integer.
Definition: item.h:144
@ lower_is_better
Lower values are better for this stat.
Definition: item.h:147
cata::value_ptr< islot_ammo > ammo
Definition: itype.h:835
#define _(msg)
Definition: translations.h:116

References _, itype::ammo, AMMO_DAMAGE_AP, AMMO_DAMAGE_AP_PROPORTIONAL, AMMO_DAMAGE_DISPERSION, AMMO_DAMAGE_PROPORTIONAL, AMMO_DAMAGE_RANGE, AMMO_DAMAGE_RECOIL, AMMO_DAMAGE_VALUE, ammo_data(), ammo_effect_BLACKPOWDER, ammo_effect_INCENDIARY, ammo_effect_NEVER_MISFIRES, ammo_effect_RECYCLED, islot_ammo::ammo_effects, AMMO_FX_BLACKPOWDER, AMMO_FX_CANTMISSFIRE, AMMO_FX_INCENDIARY, AMMO_FX_RECYCLED, ammo_remaining(), AMMO_REMAINING_OR_TYPES, AMMO_SHAPE, ammo_type(), common_ranged_data::damage, damage_instance::damage_units, common_ranged_data::dispersion, damage_instance::empty(), islot_ammo::force_stat_display, get_ranged_armor_mult(), get_ranged_pierce(), info(), insert_separation_line(), is_ammo(), iteminfo::is_decimal, is_gun(), iteminfo::lower_is_better, om_direction::name(), nname(), iteminfo::no_newline, common_ranged_data::range, islot_ammo::recoil, islot_ammo::shape, sign::space, string_format(), iteminfo_query::test(), and damage_instance::total_damage().

Referenced by info().

◆ ammo_remaining()

int item::ammo_remaining ( ) const

Quantity of ammunition currently loaded in tool, gun or auxiliary gunmod.

Definition at line 7400 of file item.cpp.

7401{
7402 const item *mag = magazine_current();
7403 if( mag ) {
7404 return mag->ammo_remaining();
7405 }
7406
7407 if( is_tool() || is_gun() ) {
7408 // includes auxiliary gunmods
7410 int power = units::to_kilojoule( get_avatar().get_power_level() );
7411 return power;
7412 }
7413 return charges;
7414 }
7415
7416 if( is_magazine() || is_bandolier() ) {
7417 int res = 0;
7418 for( const item *e : contents.all_items_top() ) {
7419 res += e->charges;
7420 }
7421 return res;
7422 }
7423
7424 return 0;
7425}

References item_contents::all_items_top(), ammo_remaining(), charges, contents, flag_USES_BIONIC_POWER(), get_avatar(), has_flag(), is_bandolier(), is_gun(), is_magazine(), is_tool(), magazine_current(), and units::to_kilojoule().

Referenced by game::add_artifact_dreams(), ammo_consume(), character_funcs::ammo_count_for(), ammo_info(), ammo_remaining(), turret_data::ammo_remaining(), vehicle_part::ammo_remaining(), vehicle_part::ammo_set(), ammo_sufficient(), item_funcs::can_be_unloaded(), turret_data::can_reload(), turret_data::can_unload(), firestarter_actor::can_use(), Character::consume_charges(), iuse::cs_lajatang_off(), Character::deactivate_bionic(), display_name(), npc::do_reload(), aim_activity_actor::do_turn(), iuse::ehandcuffs(), iuse::einktabletpc(), fill_with(), ranged::fire_gun(), character_funcs::fmt_wielded_weapon(), iuse::foodperson(), get_remaining_capacity_for_liquid(), getlight_emit(), gun_recoil(), ranged::gunmode_checks_weapon(), iuse::hand_crank(), activity_handlers::hand_crank_do_turn(), Character::has_enough_charges(), ideal_ranged_dps(), vehicle::interact_with(), is_gunmod_compatible(), is_reloadable_helper(), item(), item_action_generator::map_actions_to_items(), Item_modifier::modify(), iuse::multicooker(), iuse::oxytorch(), target_ui::panel_gun_info(), price(), game::process_artifact(), Character::process_items(), relic_funcs::process_recharge(), process_vehicle_items(), item_reload_option::qty(), iuse::radio_on(), avatar_action::reload(), reload(), activity_handlers::repair_item_finish(), item_funcs::shots_remaining(), iuse::tazer2(), tool_info(), units_remaining(), avatar_funcs::unload_item(), charger_tile::update_internal(), iuse::vibe(), activity_handlers::vibe_do_turn(), wants_to_reload(), wants_to_reload_with(), weapon_inventory_preset::weapon_inventory_preset(), and weight().

◆ ammo_required()

int item::ammo_required ( ) const

Quantity of ammunition consumed per usage of tool or with each shot of gun.

Definition at line 7470 of file item.cpp.

7471{
7472 if( is_tool() ) {
7473 return std::max( type->charges_to_use(), 0 );
7474 }
7475
7476 if( is_gun() ) {
7477 if( ammo_types().empty() ) {
7478 return 0;
7479 } else if( has_flag( flag_FIRE_100 ) ) {
7480 return 100;
7481 } else if( has_flag( flag_FIRE_50 ) ) {
7482 return 50;
7483 } else if( has_flag( flag_FIRE_20 ) ) {
7484 return 20;
7485 } else {
7486 return 1;
7487 }
7488 }
7489
7490 return 0;
7491}
static const std::string flag_FIRE_100("FIRE_100")
static const std::string flag_FIRE_50("FIRE_50")
static const std::string flag_FIRE_20("FIRE_20")
int charges_to_use() const
Definition: itype.cpp:110

References ammo_types(), itype::charges_to_use(), flag_FIRE_100(), flag_FIRE_20(), flag_FIRE_50(), has_flag(), is_gun(), is_tool(), and type.

Referenced by character_funcs::ammo_count_for(), turret_data::ammo_options(), ammo_sufficient(), firestarter_actor::can_use(), cauterize_actor::can_use(), Character::consume_charges(), salvage_actor::cut_up(), display_name(), npc::do_reload(), ranged::fire_gun(), mattack::frag(), activity_handlers::game_do_turn(), activatable_inventory_preset::get_denial(), gun_recoil(), ranged::gunmode_checks_weapon(), Character::has_enough_charges(), vehicle::interact_with(), activity_handlers::jackhammer_finish(), item_action_generator::map_actions_to_items(), iuse::oxytorch(), activity_handlers::oxytorch_do_turn(), activity_handlers::pickaxe_finish(), iuse::portable_game(), turret_data::prepare_fire(), npc::pretend_fire(), process_tool(), turret_data::query(), activity_handlers::repair_item_finish(), mattack::rifle(), item_funcs::shots_remaining(), mattack::tankgun(), units_sufficient(), inscribe_actor::use(), cauterize_actor::use(), enzlave_actor::use(), wants_to_reload(), and wants_to_reload_with().

◆ ammo_set()

item & item::ammo_set ( const itype_id ammo,
int  qty = -1 
)

Filter setting the ammo for this instance Any existing ammo is removed.

If necessary a magazine is also added.

Parameters
ammospecific type of ammo (must be compatible with item ammo type)
qtymaximum ammo (capped by item capacity) or negative to fill to capacity
Returns
same instance to allow method chaining

Definition at line 594 of file item.cpp.

595{
596 if( qty < 0 ) {
597 // completely fill an integral or existing magazine
599 qty = ammo_capacity();
600
601 // else try to add a magazine using default ammo count property if set
602 } else if( !magazine_default().is_null() ) {
603 item mag( magazine_default() );
604 if( mag.type->magazine->count > 0 ) {
605 qty = mag.type->magazine->count;
606 } else {
607 qty = item( magazine_default() ).ammo_capacity();
608 }
609 }
610 }
611
612 if( qty <= 0 ) {
613 ammo_unset();
614 return *this;
615 }
616
617 // handle reloadable tools and guns with no specific ammo type as special case
618 if( ( ammo.is_null() && ammo_types().empty() ) || is_money() ) {
619 if( ( is_tool() || is_gun() ) && magazine_integral() ) {
620 curammo = nullptr;
621 charges = std::min( qty, ammo_capacity() );
622 }
623 return *this;
624 }
625
626 // check ammo is valid for the item
627 const itype *atype = &*ammo;
628 if( !atype->ammo || !ammo_types().count( atype->ammo->type ) ) {
629 debugmsg( "Tried to set invalid ammo %s[%d] for %s", atype->get_id(), qty, typeId() );
630 return *this;
631 }
632
633 if( is_magazine() ) {
634 ammo_unset();
635 item set_ammo( ammo, calendar::turn, std::min( qty, ammo_capacity() ) );
636 if( has_flag( flag_NO_UNLOAD ) ) {
637 set_ammo.set_flag( "NO_DROP" );
638 set_ammo.set_flag( "IRREMOVABLE" );
639 }
640 put_in( set_ammo );
641
642 } else if( magazine_integral() ) {
643 curammo = atype;
644 charges = std::min( qty, ammo_capacity() );
645
646 } else {
647 if( !magazine_current() ) {
649 if( !mag->magazine ) {
650 debugmsg( "Tried to set ammo %s[%d] without suitable magazine for %s",
651 atype->get_id(), qty, typeId() );
652 return *this;
653 }
654
655 // if default magazine too small fetch instead closest available match
656 if( mag->magazine->capacity < qty ) {
657 // as above call to magazine_default successful can infer minimum one option exists
658 auto iter = type->magazines.find( atype->ammo->type );
659 if( iter == type->magazines.end() ) {
660 debugmsg( "%s doesn't have a magazine for %s",
661 typeId(), ammo );
662 return *this;
663 }
664 std::vector<itype_id> opts( iter->second.begin(), iter->second.end() );
665 std::sort( opts.begin(), opts.end(), []( const itype_id & lhs, const itype_id & rhs ) {
666 return lhs->magazine->capacity < rhs->magazine->capacity;
667 } );
668 mag = opts.back();
669 for( const itype_id &e : opts ) {
670 if( e->magazine->capacity >= qty ) {
671 mag = e;
672 break;
673 }
674 }
675 }
676 put_in( item( mag ) );
677 }
678 magazine_current()->ammo_set( ammo, qty );
679 }
680
681 return *this;
682}
bool is_money() const
Definition: item.cpp:6026
item & ammo_unset()
Filter removing all ammo from this instance If the item is neither a tool, gun nor magazine is a no-o...
Definition: item.cpp:684
bool is_null() const
Returns whether this represents the id of the null-object (in which case it's the null-id).
Definition: string_id.h:325
static const std::string flag_NO_UNLOAD("NO_UNLOAD")
std::map< ammotype, std::set< itype_id > > magazines
Magazine types (if any) for each ammo type that can be used to reload this item.
Definition: itype.h:991

References itype::ammo, ammo_capacity(), ammo_set(), ammo_types(), ammo_unset(), charges, count(), curammo, debugmsg, flag_NO_UNLOAD(), itype::get_id(), has_flag(), is_gun(), is_magazine(), is_money(), is_null(), string_id< T >::is_null(), is_tool(), item(), itype::magazine, magazine_current(), magazine_default(), magazine_integral(), itype::magazines, put_in(), set_flag(), calendar::turn, type, and typeId().

Referenced by Character::activate_bionic(), ammo_set(), vehicle_part::ammo_set(), mdeath::broken(), npc::check_toggle_cbm(), crafting::complete_disassemble(), vehicle_part::deserialize(), game::dump_stats(), fill_with(), find_reloadable_cbms(), basecamp::form_crafting_inventory(), gun_info(), npc_ai::gun_value(), activity_handlers::hand_crank_do_turn(), vehicle::interact_with(), item(), Item_modifier::modify(), relic_funcs::process_recharge_entry(), gun_actor::shoot(), npc::starting_weapon(), avatar_funcs::unload_item(), target_ui::update_ammo_range_from_gun_mode(), iuse_transform::use(), npc_ai::wielded_value(), and debug_menu::wishitem().

◆ ammo_sort_name()

std::string item::ammo_sort_name ( ) const

Definition at line 7664 of file item.cpp.

7665{
7666 if( is_magazine() || is_gun() || is_tool() ) {
7667 const std::set<ammotype> &types = ammo_types();
7668 if( !types.empty() ) {
7669 return ammotype( *types.begin() )->name();
7670 }
7671 }
7672 if( is_ammo() ) {
7673 return ammo_type()->name();
7674 }
7675 return "";
7676}
std::string name() const
Definition: ammo.cpp:79

References ammo_type(), ammo_types(), is_ammo(), is_gun(), is_magazine(), is_tool(), and ammunition_type::name().

◆ ammo_sufficient()

bool item::ammo_sufficient ( int  qty = 1) const

Check if sufficient ammo is loaded for given number of uses.

Check if there is enough ammo loaded in a tool for the given number of uses or given number of gun shots. Using this function for this check is preferred because we expect to add support for items consuming multiple ammo types in the future. Users of this function will not need to be refactored when this happens.

Parameters
[in]qtyNumber of uses
Returns
true if ammo sufficient for number of uses is loaded, false otherwise

Definition at line 7493 of file item.cpp.

7494{
7495 return ammo_remaining() >= ammo_required() * qty;
7496}
int ammo_required() const
Quantity of ammunition consumed per usage of tool or with each shot of gun.
Definition: item.cpp:7470

References ammo_remaining(), and ammo_required().

Referenced by can_do_activity_there(), iuse::extinguisher(), ranged::gunmode_checks_weapon(), Character::has_enough_charges(), iuse::jet_injector(), item_action_generator::map_actions_to_items(), mine_activity(), avatar_action::move(), iuse::pheromone(), iuse::portal(), turret_data::query(), iuse::radiocar(), iuse::radiocaron(), examine_item_menu::rate_action_use(), iuse::rm13armor_off(), iuse::shavekit(), gun_actor::shoot(), iuse::stimpack(), and iuse::teleport().

◆ ammo_type()

ammotype item::ammo_type ( ) const

Ammo type of an ammo item.

Returns
ammotype of ammo item or a null id if the item is not ammo

Definition at line 7606 of file item.cpp.

7607{
7608 if( is_ammo() ) {
7609 return type->ammo->type;
7610 }
7611 return ammotype::NULL_ID();
7612}

References itype::ammo, is_ammo(), string_id< ammunition_type >::NULL_ID(), and type.

Referenced by vehicle::add_item(), ammo_info(), ammo_sort_name(), mdeath::broken(), color_in_inventory(), detonate(), character_funcs::find_ammo_helper(), character_funcs::get_ammo_items(), item_reload_option::qty(), reload(), and npc::value().

◆ ammo_types()

const std::set< ammotype > & item::ammo_types ( bool  conversion = true) const

Set of ammo types (ammunition_type) used by item.

Parameters
conversionwhether to include the effect of any flags or mods which convert the type
Returns
empty set if item does not use a specific ammo type (and is consequently not reloadable)

Definition at line 7583 of file item.cpp.

7584{
7585 if( conversion ) {
7586 const std::vector<const item *> &mods = is_gun() ? gunmods() : toolmods();
7587 for( const item *e : mods ) {
7588 if( !e->type->mod->ammo_modifier.empty() ) {
7589 return e->type->mod->ammo_modifier;
7590 }
7591 }
7592 }
7593
7594 if( is_gun() ) {
7595 return type->gun->ammo;
7596 } else if( is_tool() ) {
7597 return type->tool->ammo_id;
7598 } else if( is_magazine() ) {
7599 return type->magazine->type;
7600 }
7601
7602 static std::set<ammotype> atypes = {};
7603 return atypes;
7604}

References itype::gun, gunmods(), is_gun(), is_magazine(), is_tool(), itype::magazine, itype::tool, toolmods(), and type.

Referenced by vehicle::add_item(), allow_crafting_component(), ammo_default(), turret_data::ammo_options(), ammo_required(), ammo_set(), ammo_sort_name(), mdeath::broken(), item_funcs::can_be_unloaded(), color_in_inventory(), common_ammo_default(), craft_has_charges(), display_name(), avatar_action::fire_wielded_weapon(), get_quality(), avatar_funcs::gunmod_add(), vehicle_part::is_battery(), is_gunmod_compatible(), is_money(), is_reloadable(), is_reloadable_helper(), item(), magazine_compatible(), magazine_default(), magazine_info(), Item_modifier::modify(), price(), relic_funcs::process_recharge_entry(), character_funcs::select_ammo(), set_countdown(), tool_info(), avatar_funcs::unload_item(), npc::value(), and weight().

◆ ammo_unset()

item & item::ammo_unset ( )

Filter removing all ammo from this instance If the item is neither a tool, gun nor magazine is a no-op For items reloading using magazines any empty magazine remains present.

Definition at line 684 of file item.cpp.

685{
686 if( !is_tool() && !is_gun() && !is_magazine() ) {
687 // do nothing
688 } else if( is_magazine() ) {
690 } else if( magazine_integral() ) {
691 curammo = nullptr;
692 charges = 0;
693 } else if( magazine_current() ) {
695 }
696
697 return *this;
698}

References ammo_unset(), charges, item_contents::clear_items(), contents, curammo, is_gun(), is_magazine(), is_tool(), magazine_current(), and magazine_integral().

Referenced by ammo_set(), ammo_unset(), vehicle_part::ammo_unset(), iuse::ehandcuffs(), emit_radio_signal(), npc_ai::gun_value(), and ammobelt_actor::use().

◆ animal_armor_info()

void item::animal_armor_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 2736 of file item.cpp.

2738{
2739 if( !is_pet_armor() ) {
2740 return;
2741 }
2742
2743 const std::string space = " ";
2744
2745 int converted_storage_scale = 0;
2746 const double converted_storage = round_up( convert_volume( get_storage().value(),
2747 &converted_storage_scale ), 2 );
2748 if( parts->test( iteminfo_parts::ARMOR_STORAGE ) && converted_storage > 0 ) {
2749 const iteminfo::flags f = converted_storage_scale == 0 ? iteminfo::no_flags : iteminfo::is_decimal;
2750 info.push_back( iteminfo( "ARMOR", space + _( "Storage: " ),
2751 string_format( "<num> %s", volume_units_abbr() ),
2752 f, converted_storage ) );
2753 }
2754
2755 // Whatever the last entry was, we want a newline at this point
2756 info.back().bNewLine = true;
2757
2758 armor_protection_info( info, parts, batch, debug );
2759}
double round_up(double val, unsigned int dp)
Round a value up at a given decimal place.
units::volume get_storage() const
Returns the storage amount (islot_armor::storage) that this item provides when worn.
Definition: item.cpp:5758
void armor_protection_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:2510
bool is_pet_armor(bool on_pet=false) const
Definition: item.cpp:6724
constexpr auto debug
Definition: options.cpp:156
Value and metadata for one property of an item.
Definition: item.h:107
flags
Definition: item.h:142
@ no_flags
Definition: item.h:143
const char * volume_units_abbr()
Create an abbreviated units label for a volume value.
double convert_volume(int volume)
Convert volume from ml to units defined by user.

References _, armor_protection_info(), ARMOR_STORAGE, convert_volume(), debug, get_storage(), info(), iteminfo::is_decimal, is_pet_armor(), iteminfo::no_flags, round_up(), sign::space, string_format(), iteminfo_query::test(), and volume_units_abbr().

Referenced by info().

◆ armor_fit_info()

void item::armor_fit_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 2761 of file item.cpp.

2763{
2764 if( !is_armor() ) {
2765 return;
2766 }
2767
2768 avatar &you = get_avatar();
2769 int encumbrance = get_encumber( you );
2770 const sizing sizing_level = get_sizing( you, encumbrance != 0 );
2771
2774 info.push_back( iteminfo( "DESCRIPTION",
2775 _( "* This item can be <info>worn with a "
2776 "helmet</info>." ) ) );
2777 }
2778
2780 switch( sizing_level ) {
2782 if( has_flag( flag_FIT ) ) {
2783 info.emplace_back( "DESCRIPTION",
2784 _( "* This clothing <info>fits</info> you perfectly." ) );
2785 }
2786 break;
2788 if( has_flag( flag_FIT ) ) {
2789 info.emplace_back( "DESCRIPTION", _( "* This clothing <info>fits</info> "
2790 "your large frame perfectly." ) );
2791 }
2792 break;
2794 if( has_flag( flag_FIT ) ) {
2795 info.emplace_back( "DESCRIPTION", _( "* This clothing <info>fits</info> "
2796 "your small frame perfectly." ) );
2797 }
2798 break;
2800 info.emplace_back( "DESCRIPTION", _( "* This clothing is <bad>oversized</bad> "
2801 "and does <bad>not fit</bad> you." ) );
2802 break;
2804 info.emplace_back( "DESCRIPTION",
2805 _( "* This clothing is hilariously <bad>oversized</bad> "
2806 "and does <bad>not fit</bad> your <info>abnormally "
2807 "small mutated anatomy</info>." ) );
2808 break;
2810 info.emplace_back( "DESCRIPTION",
2811 _( "* This clothing is <bad>normal sized</bad> and does "
2812 "<bad>not fit</info> your <info>abnormally large "
2813 "mutated anatomy</info>." ) );
2814 break;
2816 info.emplace_back( "DESCRIPTION",
2817 _( "* This clothing is <bad>normal sized</bad> and does "
2818 "<bad>not fit</bad> your <info>abnormally small "
2819 "mutated anatomy</info>." ) );
2820 break;
2822 info.emplace_back( "DESCRIPTION",
2823 _( "* This clothing is hilariously <bad>undersized</bad> "
2824 "and does <bad>not fit</bad> your <info>abnormally "
2825 "large mutated anatomy</info>." ) );
2826 break;
2828 info.emplace_back( "DESCRIPTION", _( "* This clothing is <bad>undersized</bad> "
2829 "and does <bad>not fit</bad> you." ) );
2830 break;
2831 default:
2832 break;
2833 }
2834 }
2835
2837 if( has_flag( flag_VARSIZE ) ) {
2838 std::string resize_str;
2839 if( has_flag( flag_FIT ) ) {
2840 switch( sizing_level ) {
2842 resize_str = _( "<info>can be upsized</info>" );
2843 break;
2845 resize_str = _( "<info>can be downsized</info>" );
2846 break;
2849 resize_str = _( "<bad>can not be downsized</bad>" );
2850 break;
2853 resize_str = _( "<bad>can not be upsized</bad>" );
2854 break;
2855 default:
2856 break;
2857 }
2858 if( !resize_str.empty() ) {
2859 std::string info_str = string_format( _( "* This clothing %s." ), resize_str );
2860 info.push_back( iteminfo( "DESCRIPTION", info_str ) );
2861 }
2862 } else {
2863 switch( sizing_level ) {
2865 resize_str = _( " and <info>upsized</info>" );
2866 break;
2868 resize_str = _( " and <info>downsized</info>" );
2869 break;
2872 resize_str = _( " but <bad>not downsized</bad>" );
2873 break;
2876 resize_str = _( " but <bad>not upsized</bad>" );
2877 break;
2878 default:
2879 break;
2880 }
2881 std::string info_str = string_format( _( "* This clothing <info>can be "
2882 "refitted</info>%s." ), resize_str );
2883 info.push_back( iteminfo( "DESCRIPTION", info_str ) );
2884 }
2885 } else {
2886 info.emplace_back( "DESCRIPTION", _( "* This clothing <bad>can not be refitted, "
2887 "upsized, or downsized</bad>." ) );
2888 }
2889 }
2890
2892 info.push_back( iteminfo( "DESCRIPTION",
2893 _( "* This item can be worn on <info>either side</info> of "
2894 "the body." ) ) );
2895 }
2896 if( ( is_power_armor() ) &&
2900 info.push_back( iteminfo( "DESCRIPTION",
2901 _( "* When worn with a power armor suit, it will "
2902 "<good>fully protect</good> you from "
2903 "<info>radiation</info>." ) ) );
2904 } else if( has_flag( flag_POWERARMOR_EXO ) ) {
2905 info.push_back( iteminfo( "DESCRIPTION",
2906 _( "* When worn with a power armor helmet, it will "
2907 "<good>fully protect</good> you from " "<info>radiation</info>." ) ) );
2908 }
2909 }
2910 }
2912 info.push_back( iteminfo( "DESCRIPTION",
2913 string_format( _( "* The film strip on the badge is %s." ),
2915 }
2916}
@ bp_head
Definition: bodypart.h:43
bool is_sided() const
Returns true if item is armor and can be worn on different sides of the body.
Definition: item.cpp:806
int irradiation
Definition: item.h:2217
bool is_power_armor() const
Whether this is a power armor item.
Definition: item.cpp:5812
sizing
Definition: item.h:2136
@ small_sized_small_char
@ human_sized_human_char
@ small_sized_human_char
@ human_sized_small_char
bool is_armor() const
Definition: item.cpp:6730
sizing get_sizing(const Character &, bool) const
Definition: item.cpp:1181
int get_encumber(const Character &) const
Returns the encumbrance value that this item has when worn by given player.
Definition: item.cpp:5818
bool covers(body_part bp) const
Whether this item (when worn) covers the given body part.
Definition: item.cpp:747
static const std::string flag_FIT("FIT")
static const std::string flag_HELMET_COMPAT("HELMET_COMPAT")
static const std::string flag_POWERARMOR_EXO("POWERARMOR_EXO")
static const itype_id itype_rad_badge("rad_badge")
static const std::string flag_VARSIZE("VARSIZE")
static const std::string flag_POWERARMOR_EXTERNAL("POWERARMOR_EXTERNAL")
std::string rad_badge_color(const int rad)
Definition: item.cpp:293
@ DESCRIPTION_FLAGS_POWERARMOR
@ DESCRIPTION_FLAGS_POWERARMOR_RADIATIONHINT
@ DESCRIPTION_FLAGS_HELMETCOMPAT

References _, big_sized_big_char, big_sized_human_char, big_sized_small_char, bp_head, covers(), DESCRIPTION_FLAGS_FITS, DESCRIPTION_FLAGS_HELMETCOMPAT, DESCRIPTION_FLAGS_POWERARMOR, DESCRIPTION_FLAGS_POWERARMOR_RADIATIONHINT, DESCRIPTION_FLAGS_SIDED, DESCRIPTION_FLAGS_VARSIZE, DESCRIPTION_IRRADIATION, flag_FIT(), flag_HELMET_COMPAT(), flag_POWERARMOR_EXO(), flag_POWERARMOR_EXTERNAL(), flag_VARSIZE(), get_avatar(), get_encumber(), get_sizing(), has_flag(), human_sized_big_char, human_sized_human_char, human_sized_small_char, info(), irradiation, is_armor(), is_power_armor(), is_sided(), itype_rad_badge, rad_badge_color(), small_sized_big_char, small_sized_human_char, small_sized_small_char, string_format(), iteminfo_query::test(), and typeId().

Referenced by final_info().

◆ armor_info()

void item::armor_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 2553 of file item.cpp.

2555{
2556 if( !is_armor() ) {
2557 return;
2558 }
2559
2560 avatar &you = get_avatar();
2561 int encumbrance = get_encumber( you );
2562 const sizing sizing_level = get_sizing( you, encumbrance != 0 );
2563 const std::string space = " ";
2564 body_part_set covered_parts = get_covered_body_parts();
2565 bool covers_anything = covered_parts.any();
2566
2567 if( parts->test( iteminfo_parts::ARMOR_BODYPARTS ) ) {
2569 std::string coverage = _( "<bold>Covers</bold>: " );
2570 if( covers( bp_head ) ) {
2571 coverage += _( "The <info>head</info>. " );
2572 }
2573 if( covers( bp_eyes ) ) {
2574 coverage += _( "The <info>eyes</info>. " );
2575 }
2576 if( covers( bp_mouth ) ) {
2577 coverage += _( "The <info>mouth</info>. " );
2578 }
2579 if( covers( bp_torso ) ) {
2580 coverage += _( "The <info>torso</info>. " );
2581 }
2582
2583 if( is_sided() && ( covers( bp_arm_l ) || covers( bp_arm_r ) ) ) {
2584 coverage += _( "Either <info>arm</info>. " );
2585 } else if( covers( bp_arm_l ) && covers( bp_arm_r ) ) {
2586 coverage += _( "The <info>arms</info>. " );
2587 } else if( covers( bp_arm_l ) ) {
2588 coverage += _( "The <info>left arm</info>. " );
2589 } else if( covers( bp_arm_r ) ) {
2590 coverage += _( "The <info>right arm</info>. " );
2591 }
2592
2593 if( is_sided() && ( covers( bp_hand_l ) || covers( bp_hand_r ) ) ) {
2594 coverage += _( "Either <info>hand</info>. " );
2595 } else if( covers( bp_hand_l ) && covers( bp_hand_r ) ) {
2596 coverage += _( "The <info>hands</info>. " );
2597 } else if( covers( bp_hand_l ) ) {
2598 coverage += _( "The <info>left hand</info>. " );
2599 } else if( covers( bp_hand_r ) ) {
2600 coverage += _( "The <info>right hand</info>. " );
2601 }
2602
2603 if( is_sided() && ( covers( bp_leg_l ) || covers( bp_leg_r ) ) ) {
2604 coverage += _( "Either <info>leg</info>. " );
2605 } else if( covers( bp_leg_l ) && covers( bp_leg_r ) ) {
2606 coverage += _( "The <info>legs</info>. " );
2607 } else if( covers( bp_leg_l ) ) {
2608 coverage += _( "The <info>left leg</info>. " );
2609 } else if( covers( bp_leg_r ) ) {
2610 coverage += _( "The <info>right leg</info>. " );
2611 }
2612
2613 if( is_sided() && ( covers( bp_foot_l ) || covers( bp_foot_r ) ) ) {
2614 coverage += _( "Either <info>foot</info>. " );
2615 } else if( covers( bp_foot_l ) && covers( bp_foot_r ) ) {
2616 coverage += _( "The <info>feet</info>. " );
2617 } else if( covers( bp_foot_l ) ) {
2618 coverage += _( "The <info>left foot</info>. " );
2619 } else if( covers( bp_foot_r ) ) {
2620 coverage += _( "The <info>right foot</info>. " );
2621 }
2622
2623 if( !covers_anything ) {
2624 coverage += _( "<info>Nothing</info>." );
2625 }
2626
2627 info.push_back( iteminfo( "ARMOR", coverage ) );
2628 }
2629
2630 if( parts->test( iteminfo_parts::ARMOR_LAYER ) && covers_anything ) {
2631 std::string layering = _( "Layer: " );
2632 if( has_flag( flag_PERSONAL ) ) {
2633 layering += _( "<stat>Personal aura</stat>. " );
2634 } else if( has_flag( flag_SKINTIGHT ) ) {
2635 layering += _( "<stat>Close to skin</stat>. " );
2636 } else if( has_flag( flag_BELTED ) ) {
2637 layering += _( "<stat>Strapped</stat>. " );
2638 } else if( has_flag( flag_OUTER ) ) {
2639 layering += _( "<stat>Outer</stat>. " );
2640 } else if( has_flag( flag_WAIST ) ) {
2641 layering += _( "<stat>Waist</stat>. " );
2642 } else if( has_flag( flag_AURA ) ) {
2643 layering += _( "<stat>Outer aura</stat>. " );
2644 } else {
2645 layering += _( "<stat>Normal</stat>. " );
2646 }
2647
2648 info.push_back( iteminfo( "ARMOR", layering ) );
2649 }
2650
2651 if( parts->test( iteminfo_parts::ARMOR_COVERAGE ) && covers_anything ) {
2652 info.push_back( iteminfo( "ARMOR", _( "Coverage: " ), "<num>%",
2654 }
2655 if( parts->test( iteminfo_parts::ARMOR_WARMTH ) && covers_anything ) {
2656 info.push_back( iteminfo( "ARMOR", space + _( "Warmth: " ), get_warmth() ) );
2657 }
2658
2660
2661 if( parts->test( iteminfo_parts::ARMOR_ENCUMBRANCE ) && covers_anything ) {
2662 std::string format;
2663 if( has_flag( flag_FIT ) ) {
2664 format = _( "<num> <info>(fits)</info>" );
2665 } else if( has_flag( flag_VARSIZE ) && encumbrance ) {
2666 format = _( "<num> <bad>(poor fit)</bad>" );
2667 }
2668
2669 //If we have the wrong size, we do not fit so alert the player
2670 if( sizing_level == sizing::human_sized_small_char ) {
2671 format = _( "<num> <bad>(too big)</bad>" );
2672 } else if( sizing_level == sizing::big_sized_small_char ) {
2673 format = _( "<num> <bad>(huge!)</bad>" );
2674 } else if( sizing_level == sizing::small_sized_human_char ||
2675 sizing_level == sizing::human_sized_big_char ) {
2676 format = _( "<num> <bad>(too small)</bad>" );
2677 } else if( sizing_level == sizing::small_sized_big_char ) {
2678 format = _( "<num> <bad>(tiny!)</bad>" );
2679 }
2680
2681 info.push_back( iteminfo( "ARMOR", _( "<bold>Encumbrance</bold>: " ), format,
2683 encumbrance ) );
2684 if( !type->rigid ) {
2685 const int encumbrance_when_full =
2687 info.push_back( iteminfo( "ARMOR", space + _( "Encumbrance when full: " ), "",
2689 encumbrance_when_full ) );
2690 }
2691 }
2692
2693 int converted_storage_scale = 0;
2694 const double converted_storage = round_up( convert_volume( get_storage().value(),
2695 &converted_storage_scale ), 2 );
2696 if( parts->test( iteminfo_parts::ARMOR_STORAGE ) && converted_storage > 0 ) {
2697 const iteminfo::flags f = converted_storage_scale == 0 ? iteminfo::no_flags : iteminfo::is_decimal;
2698 info.push_back( iteminfo( "ARMOR", space + _( "Storage: " ),
2699 string_format( "<num> %s", volume_units_abbr() ),
2700 f, converted_storage ) );
2701 }
2702
2703 // Whatever the last entry was, we want a newline at this point
2704 info.back().bNewLine = true;
2705
2706 if( covers_anything ) {
2707 armor_protection_info( info, parts, batch, debug );
2708 }
2709
2710 const units::mass weight_bonus = get_weight_capacity_bonus();
2711 const float weight_modif = get_weight_capacity_modifier();
2712 if( weight_modif != 1 ) {
2713 std::string modifier;
2714 if( weight_modif < 1 ) {
2715 modifier = "<num><bad>x</bad>";
2716 } else {
2717 modifier = "<num><color_light_green>x</color>";
2718 }
2719 info.push_back( iteminfo( "ARMOR",
2720 _( "<bold>Weight capacity modifier</bold>: " ), modifier,
2721 iteminfo::no_newline | iteminfo::is_decimal, weight_modif ) );
2722 }
2723 if( weight_bonus != 0_gram ) {
2724 std::string bonus;
2725 if( weight_bonus < 0_gram ) {
2726 bonus = string_format( "<num> <bad>%s</bad>", weight_units() );
2727 } else {
2728 bonus = string_format( "<num> <color_light_green> %s</color>", weight_units() );
2729 }
2730 info.push_back( iteminfo( "ARMOR", _( "<bold>Weight capacity bonus</bold>: " ), bonus,
2732 convert_weight( weight_bonus ) ) );
2733 }
2734}
@ bp_foot_l
Definition: bodypart.h:52
@ bp_leg_r
Definition: bodypart.h:51
@ bp_eyes
Definition: bodypart.h:44
@ bp_hand_l
Definition: bodypart.h:48
@ bp_arm_l
Definition: bodypart.h:46
@ bp_leg_l
Definition: bodypart.h:50
@ bp_hand_r
Definition: bodypart.h:49
@ bp_torso
Definition: bodypart.h:42
@ bp_mouth
Definition: bodypart.h:45
@ bp_foot_r
Definition: bodypart.h:53
@ bp_arm_r
Definition: bodypart.h:47
bool any() const
Definition: bodypart.h:265
units::volume get_total_capacity() const
It returns the maximum volume of any contents, including liquids, ammo, magazines,...
Definition: item.cpp:8426
int get_encumber_when_containing(const Character &, const units::volume &contents_volume) const
Returns the encumbrance value that this item has when worn by given player, when containing a particu...
Definition: item.cpp:5846
units::mass get_weight_capacity_bonus() const
Returns the weight capacity bonus (islot_armor::weight_capacity_modifier) that this item provides whe...
Definition: item.cpp:5780
body_part_set get_covered_body_parts() const
Bitset of all covered body parts.
Definition: item.cpp:757
int get_warmth() const
Returns the warmth value that this item has when worn.
Definition: item.cpp:5944
int get_coverage() const
Returns the relative coverage that this item has when worn.
Definition: item.cpp:5926
float get_weight_capacity_modifier() const
Returns the weight capacity modifier (islot_armor::weight_capacity_modifier) that this item provides ...
Definition: item.cpp:5771
FMT_INLINE std::basic_string< Char > format(const S &format_str, Args &&... args)
\rst Formats arguments and returns the result as a string.
Definition: fmtlib_core.h:2316
static const std::string flag_WAIST("WAIST")
static const std::string flag_BELTED("BELTED")
static const std::string flag_SKINTIGHT("SKINTIGHT")
static const std::string flag_OUTER("OUTER")
static const std::string flag_AURA("AURA")
static const std::string flag_PERSONAL("PERSONAL")
bool rigid
Definition: itype.h:962
const char * weight_units()
Create a units label for a weight value.
double convert_weight(const units::mass &weight)
Convert weight in grams to units defined by user (kg or lbs)

References _, body_part_set::any(), ARMOR_BODYPARTS, ARMOR_COVERAGE, ARMOR_ENCUMBRANCE, ARMOR_LAYER, armor_protection_info(), ARMOR_STORAGE, ARMOR_WARMTH, big_sized_small_char, bp_arm_l, bp_arm_r, bp_eyes, bp_foot_l, bp_foot_r, bp_hand_l, bp_hand_r, bp_head, bp_leg_l, bp_leg_r, bp_mouth, bp_torso, convert_volume(), convert_weight(), covers(), debug, flag_AURA(), flag_BELTED(), flag_FIT(), flag_OUTER(), flag_PERSONAL(), flag_SKINTIGHT(), flag_VARSIZE(), flag_WAIST(), format(), get_avatar(), get_coverage(), get_covered_body_parts(), get_encumber(), get_encumber_when_containing(), get_sizing(), get_storage(), get_total_capacity(), get_warmth(), get_weight_capacity_bonus(), get_weight_capacity_modifier(), has_flag(), human_sized_big_char, human_sized_small_char, info(), insert_separation_line(), is_armor(), iteminfo::is_decimal, is_sided(), iteminfo::lower_is_better, iteminfo::no_flags, iteminfo::no_newline, itype::rigid, round_up(), small_sized_big_char, small_sized_human_char, sign::space, string_format(), iteminfo_query::test(), type, volume_units_abbr(), and weight_units().

Referenced by info().

◆ armor_protection_info()

void item::armor_protection_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 2510 of file item.cpp.

2513{
2514 if( !is_armor() && !is_pet_armor() ) {
2515 return;
2516 }
2517
2518 const std::string space = " ";
2519
2520 if( parts->test( iteminfo_parts::ARMOR_PROTECTION ) ) {
2521 info.push_back( iteminfo( "ARMOR", _( "<bold>Protection</bold>: Bash: " ), "",
2523 info.push_back( iteminfo( "ARMOR", space + _( "Cut: " ), "", iteminfo::no_newline, cut_resist() ) );
2524 info.push_back( iteminfo( "ARMOR", space + _( "Ballistic: " ), bullet_resist() ) );
2525 info.push_back( iteminfo( "ARMOR", space + _( "Acid: " ), "",
2527 info.push_back( iteminfo( "ARMOR", space + _( "Fire: " ), "",
2529 info.push_back( iteminfo( "ARMOR", space + _( "Environmental: " ),
2530 get_base_env_resist( *this ) ) );
2531 if( type->can_use( "GASMASK" ) || type->can_use( "DIVE_TANK" ) ) {
2532 info.push_back( iteminfo( "ARMOR",
2533 _( "<bold>Protection when active</bold>: " ) ) );
2534 info.push_back( iteminfo( "ARMOR", space + _( "Acid: " ), "",
2537 info.push_back( iteminfo( "ARMOR", space + _( "Fire: " ), "",
2540 info.push_back( iteminfo( "ARMOR", space + _( "Environmental: " ),
2542 }
2543
2544 if( damage() > 0 ) {
2545 info.push_back( iteminfo( "ARMOR",
2546 _( "Protection values are <bad>reduced by damage</bad> and "
2547 "you may be able to <info>improve them by repairing this "
2548 "item</info>." ) ) );
2549 }
2550 }
2551}
int bash_resist(bool to_self=false) const
Definition: item.cpp:6057
int fire_resist(bool to_self=false, int base_env_resist=0) const
Definition: item.cpp:6187
int acid_resist(bool to_self=false, int base_env_resist=0) const
Resistance against different damage types (damage_type).
Definition: item.cpp:6153
int bullet_resist(bool to_self=false) const
Definition: item.cpp:6124
int get_base_env_resist_w_filter() const
Returns the base resistance to environmental effects if an item (for example a gas mask) requires a g...
Definition: item.cpp:5803
int cut_resist(bool to_self=false) const
Definition: item.cpp:6085
int damage() const
How much damage has the item sustained?
Definition: item.cpp:700
static int get_base_env_resist(const item &it)
Definition: item.cpp:1224
bool can_use(const std::string &iuse_name) const
Definition: itype.cpp:161

References _, acid_resist(), ARMOR_PROTECTION, bash_resist(), bullet_resist(), itype::can_use(), cut_resist(), damage(), fire_resist(), get_base_env_resist(), get_base_env_resist_w_filter(), get_env_resist(), info(), is_armor(), is_pet_armor(), iteminfo::no_newline, sign::space, iteminfo_query::test(), and type.

Referenced by animal_armor_info(), and armor_info().

◆ attack_cost()

int item::attack_cost ( ) const

Base number of moves (Creature::moves) that a single melee attack with this items takes.

The actual time depends heavily on the attacker, see melee.cpp.

Definition at line 5207 of file item.cpp.

5208{
5209 int base = 65 + ( volume() / 62.5_ml + weight() / 60_gram ) / count();
5211 return std::max( 0, base + bonus );
5212}
double bonus_from_enchantments_wielded(double base, enchant_vals::mod value, bool round=false) const
Calculate bonus from enchantments that affect this item only, assume it's wielded and all enchantment...
Definition: item.cpp:7032
units::mass weight(bool include_contents=true, bool integral=false) const
Definition: item.cpp:4984
units::volume volume(bool integral=false) const
Total volume of an item accounting for all contained/integrated items NOTE: Result is rounded up to n...
Definition: item.cpp:5130

References bonus_from_enchantments_wielded(), count(), enchant_vals::ITEM_ATTACK_COST, volume(), and weight().

Referenced by Character::attack_cost(), combat_info(), Character::melee_attack(), npc::move_to(), smash(), and ranged::throw_cost().

◆ average_dps()

double item::average_dps ( const player guy) const

return the average dps of the weapon against evaluation monsters

Definition at line 1452 of file item.cpp.

1453{
1454 double dmg_count = 0.0;
1455 const std::map<std::string, double> &dps_data = dps( false, true, guy );
1456 for( const std::pair<const std::string, double> &dps_entry : dps_data ) {
1457 dmg_count += dps_entry.second;
1458 }
1459 return dmg_count / dps_data.size();
1460}
std::map< std::string, double > dps(bool for_display, bool for_calc, const player &guy) const
calculate effective dps against a stock set of monsters.
Definition: item.cpp:1432

References dps().

Referenced by npc_ai::melee_value().

◆ base_damage_melee()

damage_instance item::base_damage_melee ( ) const

All damage types this item deals when used in melee (no skill modifiers etc.

applied).

Definition at line 5270 of file item.cpp.

5271{
5272 // TODO: Caching
5274 for( size_t i = DT_NULL + 1; i < NUM_DT; i++ ) {
5275 damage_type dt = static_cast<damage_type>( i );
5276 int dam = damage_melee( dt );
5277 if( dam > 0 ) {
5278 ret.add_damage( dt, dam );
5279 }
5280 }
5281
5282 return ret;
5283}
int damage_melee(damage_type dt) const
Damage of given type caused when this item is used as melee weapon.
Definition: item.cpp:5214
damage_type
Definition: damage.h:20
@ DT_NULL
Definition: damage.h:21
@ NUM_DT
Definition: damage.h:32

References damage_melee(), DT_NULL, NUM_DT, and cata::hash64_detail::ret.

◆ base_damage_thrown()

damage_instance item::base_damage_thrown ( ) const

All damage types this item deals when thrown (no skill modifiers etc.

applied).

Definition at line 5285 of file item.cpp.

5286{
5287 // TODO: Create a separate cache for individual items (for modifiers like diamond etc.)
5288 return type->thrown_damage;
5289}
damage_instance thrown_damage
Base damage output when thrown.
Definition: itype.h:967

References itype::thrown_damage, and type.

Referenced by ranged::throw_item().

◆ base_volume()

units::volume item::base_volume ( ) const

Simplified, faster volume check for when processing time is important and exact volume is not.

NOTE: Result is rounded up to next nearest milliliter when working with stackable (count_by_charges) items that have fractional volume per charge. If trying to determine how many of an item can fit in a given space, charges_per_volume should be used instead.

Definition at line 5102 of file item.cpp.

5103{
5104 if( is_null() ) {
5105 return 0_ml;
5106 }
5107 if( is_corpse() ) {
5108 return corpse_volume( corpse );
5109 }
5110
5111 if( is_craft() ) {
5112 units::volume ret = 0_ml;
5113 for( const item &it : components ) {
5114 ret += it.base_volume();
5115 }
5116 return ret;
5117 }
5118
5119 if( count_by_charges() ) {
5120 if( type->volume % type->stack_size == 0_ml ) {
5121 return type->volume / type->stack_size;
5122 } else {
5123 return type->volume / type->stack_size + 1_ml;
5124 }
5125 }
5126
5127 return type->volume;
5128}
bool count_by_charges() const
Definition: item.cpp:6031
units::volume corpse_volume(const mtype *corpse) const
Volume check for corpses, helper for base_volume().
Definition: item.cpp:5080
bool is_craft() const
Definition: item.cpp:6949
bool is_corpse() const
Whether this is a corpse item.
Definition: item.cpp:6646
int stack_size
Number of items per above volume for count_by_charges items.
Definition: itype.h:953
units::volume volume
Space occupied by items of this type CAUTION: value given is for a default-sized stack.
Definition: itype.h:945

References components, corpse, corpse_volume(), count_by_charges(), is_corpse(), is_craft(), is_null(), cata::hash64_detail::ret, itype::stack_size, type, and itype::volume.

Referenced by burn(), flammable(), and simulate_burn().

◆ bash_resist()

int item::bash_resist ( bool  to_self = false) const

Definition at line 6057 of file item.cpp.

6058{
6059 if( is_null() ) {
6060 return 0;
6061 }
6062
6063 float resist = 0;
6065 int eff_thickness = 1;
6066
6067 // base resistance
6068 // Don't give reinforced items +armor, just more resistance to ripping
6069 const int dmg = damage_level( 4 );
6070 const int eff_damage = to_self ? std::min( dmg, 0 ) : std::max( dmg, 0 );
6071 eff_thickness = std::max( 1, get_thickness() - eff_damage );
6072
6073 const std::vector<const material_type *> mat_types = made_of_types();
6074 if( !mat_types.empty() ) {
6075 for( const material_type *mat : mat_types ) {
6076 resist += mat->bash_resist();
6077 }
6078 // Average based on number of materials.
6079 resist /= mat_types.size();
6080 }
6081
6082 return std::lround( ( resist * eff_thickness ) + mod );
6083}
int get_thickness() const
Returns the islot_armor::thickness value, or 0 for non-armor.
Definition: item.cpp:5935
int damage_level(int max) const
Scale item damage to the given number of levels.
Definition: item.cpp:705
@ clothing_mod_type_bash
Definition: clothing_mod.h:19
STL namespace.

References clothing_mod_type_bash, damage_level(), get_clothing_mod_val(), get_thickness(), is_null(), and made_of_types().

Referenced by armor_inventory_preset::armor_inventory_preset(), armor_protection_info(), anonymous_namespace{armor_layers.cpp}::clothing_protection(), damage_resist(), and sew_advanced_actor::use().

◆ basic_info()

void item::basic_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 1462 of file item.cpp.

1464{
1466 info.emplace_back( "BASE", string_format( _( "<stat>Origin: %s</stat>" ),
1467 enumerate_as_string( type->src.begin(),
1468 type->src.end(), []( const std::pair<itype_id, mod_id> &source ) {
1469 return string_format( "'%s'", source.second->name() );
1472 }
1474 info.emplace_back( "BASE", colorize( string_format( "[%s]", type->get_id() ), c_light_blue ) );
1476 }
1477
1478 const std::string space = " ";
1479 if( parts->test( iteminfo_parts::BASE_MATERIAL ) ) {
1480 const std::vector<const material_type *> mat_types = made_of_types();
1481 if( !mat_types.empty() ) {
1482 const std::string material_list = enumerate_as_string( mat_types.begin(), mat_types.end(),
1483 []( const material_type * material ) {
1484 return string_format( "<stat>%s</stat>", material->name() );
1486 info.push_back( iteminfo( "BASE", string_format( _( "Material: %s" ), material_list ) ) );
1487 }
1488 }
1489 if( parts->test( iteminfo_parts::BASE_VOLUME ) ) {
1490 int converted_volume_scale = 0;
1491 const double converted_volume = round_up( convert_volume( volume().value(),
1492 &converted_volume_scale ) * batch, 3 );
1494 if( converted_volume_scale != 0 ) {
1496 }
1497 info.push_back( iteminfo( "BASE", _( "Volume: " ),
1498 string_format( "<num> %s", volume_units_abbr() ),
1499 f, converted_volume ) );
1500 }
1501 if( parts->test( iteminfo_parts::BASE_WEIGHT ) ) {
1502 info.push_back( iteminfo( "BASE", space + _( "Weight: " ),
1503 string_format( "<num> %s", weight_units() ),
1505 convert_weight( weight() ) * batch ) );
1506 }
1507 if( !owner.is_null() ) {
1508 info.push_back( iteminfo( "BASE", string_format( _( "Owner: %s" ),
1509 _( get_owner_name() ) ) ) );
1510 }
1511 if( parts->test( iteminfo_parts::BASE_CATEGORY ) ) {
1512 info.push_back( iteminfo( "BASE", _( "Category: " ),
1513 "<header>" + get_category().name() + "</header>" ) );
1514 }
1515 if( !type->weapon_category.empty() && parts->test( iteminfo_parts::WEAPON_CATEGORY ) ) {
1516 const std::string weapon_categories = enumerate_as_string( type->weapon_category.begin(),
1517 type->weapon_category.end(), [&]( const weapon_category_id & elem ) {
1518 return elem->name().translated();
1520 info.push_back( iteminfo( "BASE", _( "Weapon Category: " ),
1521 "<header>" + weapon_categories + "</header>" ) );
1522 }
1523
1524 if( parts->test( iteminfo_parts::DESCRIPTION ) ) {
1526 const std::map<std::string, std::string>::const_iterator idescription =
1527 item_vars.find( "description" );
1528 const std::optional<translation> snippet = SNIPPET.get_snippet_by_id( snip_id );
1529 if( snippet.has_value() ) {
1530 // Just use the dynamic description
1531 info.push_back( iteminfo( "DESCRIPTION", snippet.value().translated() ) );
1532 } else if( idescription != item_vars.end() ) {
1533 info.push_back( iteminfo( "DESCRIPTION", idescription->second ) );
1534 } else {
1535 if( has_flag( "MAGIC_FOCUS" ) ) {
1536 info.push_back( iteminfo( "DESCRIPTION",
1537 _( "This item is a <info>magical focus</info>. "
1538 "You can cast spells with it in your hand." ) ) );
1539 }
1540 if( is_craft() ) {
1541 const std::string desc = _( "This is an in progress %s. "
1542 "It is %d percent complete." );
1543 const int percent_progress = item_counter / 100000;
1544 info.push_back( iteminfo( "DESCRIPTION", string_format( desc,
1545 craft_data_->making->result_name(),
1546 percent_progress ) ) );
1547 } else {
1548 info.push_back( iteminfo( "DESCRIPTION", type->description.translated() ) );
1549 }
1550 }
1552 }
1553
1555
1556 if( parts->test( iteminfo_parts::BASE_REQUIREMENTS ) ) {
1557 // Display any minimal stat or skill requirements for the item
1558 std::vector<std::string> req;
1559 if( get_min_str() > 0 ) {
1560 avatar &viewer = get_avatar();
1561 if( has_flag( flag_STR_DRAW ) && ranged::get_str_draw_penalty( *this, viewer ) < 1.0f ) {
1562 if( ranged::get_str_draw_penalty( *this, viewer ) < 0.5f ) {
1563 req.push_back( string_format( _( "%s %d <color_magenta>(Can't use!)</color>" ), _( "strength" ),
1564 get_min_str() ) );
1565 } else if( ranged::get_str_draw_penalty( *this, viewer ) < 0.75f ) {
1566 req.push_back( string_format( "%s %d <color_red>(Damage/Range 0.5x, Dispersion 2.0x)</color>",
1567 _( "strength" ), get_min_str() ) );
1568 } else {
1569 req.push_back( string_format( "%s %d <color_yellow>(Damage/Range 0.75x)</color>", _( "strength" ),
1570 get_min_str() ) );
1571 }
1572 } else {
1573 req.push_back( string_format( "%s %d", _( "strength" ), get_min_str() ) );
1574 }
1575 }
1576 if( type->min_dex > 0 ) {
1577 req.push_back( string_format( "%s %d", _( "dexterity" ), type->min_dex ) );
1578 }
1579 if( type->min_int > 0 ) {
1580 req.push_back( string_format( "%s %d", _( "intelligence" ), type->min_int ) );
1581 }
1582 if( type->min_per > 0 ) {
1583 req.push_back( string_format( "%s %d", _( "perception" ), type->min_per ) );
1584 }
1585 for( const std::pair<const skill_id, int> sk : sorted_lex( type->min_skills ) ) {
1586 req.push_back( string_format( "%s %d", skill_id( sk.first )->name(), sk.second ) );
1587 }
1588 if( !req.empty() ) {
1589 info.emplace_back( "BASE", _( "<bold>Minimum requirements</bold>:" ) );
1590 info.emplace_back( "BASE", enumerate_as_string( req ) );
1592 }
1593 }
1594
1595 if( has_var( "contained_name" ) && parts->test( iteminfo_parts::BASE_CONTENTS ) ) {
1596 info.push_back( iteminfo( "BASE", string_format( _( "Contains: %s" ),
1597 get_var( "contained_name" ) ) ) );
1598 }
1599 if( count_by_charges() && !is_food() && !is_medication() &&
1600 parts->test( iteminfo_parts::BASE_AMOUNT ) ) {
1601 info.push_back( iteminfo( "BASE", _( "Amount: " ), "<num>", iteminfo::no_flags,
1602 charges * batch ) );
1603 }
1604 if( debug && parts->test( iteminfo_parts::BASE_DEBUG ) ) {
1605 if( g != nullptr ) {
1606 info.push_back( iteminfo( "BASE", string_format( "itype_id: %s",
1607 typeId().c_str() ) ) );
1608 info.push_back( iteminfo( "BASE", _( "age (hours): " ), "", iteminfo::lower_is_better,
1609 to_hours<int>( age() ) ) );
1610 info.push_back( iteminfo( "BASE", _( "charges: " ), "", iteminfo::lower_is_better,
1611 charges ) );
1612 info.push_back( iteminfo( "BASE", _( "damage: " ), "", iteminfo::lower_is_better,
1613 damage_ ) );
1614 info.push_back( iteminfo( "BASE", _( "active: " ), "", iteminfo::lower_is_better,
1615 active ) );
1616 info.push_back( iteminfo( "BASE", _( "burn: " ), "", iteminfo::lower_is_better,
1617 burnt ) );
1618 const std::string tags_listed = enumerate_as_string( item_tags, enumeration_conjunction::none );
1619 info.push_back( iteminfo( "BASE", string_format( _( "tags: %s" ), tags_listed ) ) );
1620 for( auto const &imap : item_vars ) {
1621 info.push_back( iteminfo( "BASE",
1622 string_format( _( "item var: %s, %s" ), imap.first,
1623 imap.second ) ) );
1624 }
1625
1626 const item *food = get_food();
1627 if( food && food->goes_bad() ) {
1628 info.push_back( iteminfo( "BASE", _( "age (turns): " ),
1630 to_turns<int>( food->age() ) ) );
1631 info.push_back( iteminfo( "BASE", _( "rot (turns): " ),
1633 to_turns<int>( food->rot ) ) );
1634 info.push_back( iteminfo( "BASE", space + _( "max rot (turns): " ),
1636 to_turns<int>( food->get_shelf_life() ) ) );
1637 info.push_back( iteminfo( "BASE", _( "last rot: " ),
1639 to_turn<int>( food->last_rot_check ) ) );
1640 }
1641 }
1642 }
1643}
bool display_object_ids
Display internal IDs for items, furniture, terrain and monsters.
bool display_mod_source
Display mod source for items, furniture, terrain and monsters.
double get_var(const std::string &name, double default_value) const
Definition: item.cpp:1034
int burnt
Definition: item.h:2213
int get_min_str() const
Definition: item.cpp:10074
bool has_var(const std::string &name) const
Whether the variable is defined at all.
Definition: item.cpp:1079
time_duration age() const
Definition: item.cpp:10035
time_duration rot
Accumulated rot, expressed as time the item has been in standard temperature.
Definition: item.h:2233
faction_id owner
Definition: item.h:2239
bool is_medication() const
Definition: item.cpp:6624
time_duration get_shelf_life() const
Get the shelf life of the item.
Definition: item.cpp:5545
int damage_
Definition: item.h:2242
item * get_food()
Definition: item.cpp:6668
const item_category & get_category() const
Definition: item.cpp:8708
FlagsSetType item_tags
Definition: item.h:2177
std::string get_owner_name() const
Definition: item.cpp:1265
std::optional< translation > get_snippet_by_id(const snippet_id &id) const
Returns the snippet referenced by the id, or std::nullopt if there is no snippet with such id.
std::string translated(int num=1) const
Returns raw string if no translation is needed, otherwise returns the translated string.
std::string colorize(const std::string &text, const nc_color &color)
Definition: color.cpp:669
#define c_light_blue
Definition: color.h:29
std::unique_ptr< game > g
Definition: game.cpp:285
static const std::string flag_STR_DRAW("STR_DRAW")
std::vector< material_type > material_list
Definition: material.h:23
float get_str_draw_penalty(const item &it, const Character &p)
Penalties potentially incurred by STR_DRAW weapons.
Definition: ranged.cpp:1020
std::string enumerate_as_string(const _Container &values, enumeration_conjunction conj=enumeration_conjunction::and_)
Definition: output.h:637
std::vector< std::pair< K, V > > sorted_lex(Col col)
Returns vector sorted by lexicographic order of string_id.
@ is_three_decimal
Print as decimal with three points of precision.
Definition: item.h:145
int min_dex
Definition: itype.h:909
std::set< weapon_category_id > weapon_category
Definition: itype.h:876
int min_int
Definition: itype.h:910
int min_per
Definition: itype.h:911
translation description
Definition: itype.h:879
std::map< skill_id, int > min_skills
Definition: itype.h:907
std::vector< std::pair< itype_id, mod_id > > src
Definition: itype.h:810

References _, active, age(), arrow, BASE_AMOUNT, BASE_CATEGORY, BASE_CONTENTS, BASE_DEBUG, BASE_ID, BASE_MATERIAL, BASE_MOD_SRC, BASE_REQUIREMENTS, BASE_VOLUME, BASE_WEIGHT, burnt, c_light_blue, charges, colorize(), convert_volume(), convert_weight(), count_by_charges(), craft_data_, damage_, debug, DESCRIPTION, itype::description, display_mod_source, display_object_ids, enumerate_as_string(), flag_STR_DRAW(), g, get_avatar(), get_category(), get_food(), itype::get_id(), get_min_str(), get_owner_name(), get_shelf_life(), snippet_library::get_snippet_by_id(), ranged::get_str_draw_penalty(), get_var(), goes_bad(), has_flag(), has_var(), info(), insert_separation_line(), is_craft(), iteminfo::is_decimal, is_food(), is_medication(), string_id< T >::is_null(), iteminfo::is_three_decimal, item_counter, item_tags, item_vars, last_rot_check, iteminfo::lower_is_better, made_of_types(), itype::min_dex, itype::min_int, itype::min_per, itype::min_skills, om_direction::name(), iteminfo::no_flags, iteminfo::no_newline, none, owner, rot, round_up(), skill_id, snip_id, SNIPPET, sorted_lex(), sign::space, itype::src, string_format(), iteminfo_query::test(), translation::translated(), type, typeId(), volume(), volume_units_abbr(), WEAPON_CATEGORY, itype::weapon_category, weight(), and weight_units().

Referenced by info().

◆ battery_info()

void item::battery_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3083 of file item.cpp.

3085{
3086 if( !is_battery() ) {
3087 return;
3088 }
3089
3090 std::string info_string;
3091 if( type->battery->max_capacity < 1_kJ ) {
3092 info_string = string_format( _( "<bold>Capacity</bold>: %dJ" ),
3093 to_joule( type->battery->max_capacity ) );
3094 } else if( type->battery->max_capacity >= 1_kJ ) {
3095 info_string = string_format( _( "<bold>Capacity</bold>: %dkJ" ),
3096 to_kilojoule( type->battery->max_capacity ) );
3097 }
3099 info.emplace_back( "BATTERY", info_string );
3100}
bool is_battery() const
Definition: item.cpp:6588
std::string info_string() const
As info, but as a string rather than a vector of properties.
Definition: item.cpp:4087
constexpr value_type to_joule(const quantity< value_type, energy_in_joule_tag > &v)
Definition: units_energy.h:40
cata::value_ptr< islot_battery > battery
Definition: itype.h:833

References _, itype::battery, info(), info_string(), insert_separation_line(), is_battery(), string_format(), units::to_joule(), units::to_kilojoule(), and type.

Referenced by info().

◆ bionic_info()

void item::bionic_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3296 of file item.cpp.

3298{
3299 if( !is_bionic() ) {
3300 return;
3301 }
3302
3303 // TODO: Unhide when enforcing limits
3304 if( get_option < bool >( "CBM_SLOTS_ENABLED" )
3306 info.push_back( iteminfo( "DESCRIPTION", list_occupied_bps( type->bionic->id,
3307 _( "This bionic is installed in the following body "
3308 "part(s):" ) ) ) );
3309 }
3311
3312 const bionic_id bid = type->bionic->id;
3313 const std::vector<itype_id> &fuels = bid->fuel_opts;
3314 if( !fuels.empty() ) {
3315 const int &fuel_numb = fuels.size();
3316
3317 info.push_back( iteminfo( "DESCRIPTION",
3318 vgettext( "* This bionic can produce power from the following fuel: ",
3319 "* This bionic can produce power from the following fuels: ",
3320 fuel_numb ) + enumerate_as_string( fuels.begin(),
3321 fuels.end(), []( const itype_id & id ) -> std::string { return "<info>" + id->nname( 1 ) + "</info>"; } ) ) );
3322 }
3323
3325
3326 if( bid->capacity > 0_J ) {
3327 info.push_back( iteminfo( "CBM", _( "<bold>Power Capacity</bold>:" ), _( " <num> J" ),
3329 units::to_joule( bid->capacity ) ) );
3330 }
3331
3333
3334 if( !bid->encumbrance.empty() ) {
3335 info.push_back( iteminfo( "DESCRIPTION", _( "<bold>Encumbrance</bold>: " ),
3337 for( const std::pair< const bodypart_str_id, int > element : sorted_lex( bid->encumbrance ) ) {
3338 info.push_back( iteminfo( "CBM", body_part_name_as_heading( element.first->token, 1 ),
3339 " <num> ", iteminfo::no_newline, element.second ) );
3340 }
3341 }
3342
3343 if( !bid->env_protec.empty() ) {
3344 info.push_back( iteminfo( "DESCRIPTION",
3345 bid->activated ? _( "<bold>Environmental Protection (activated)</bold>: " ) :
3346 _( "<bold>Environmental Protection</bold>: " ),
3348 for( const std::pair< const bodypart_str_id, int > element : sorted_lex( bid->env_protec ) ) {
3349 info.push_back( iteminfo( "CBM", body_part_name_as_heading( element.first->token, 1 ),
3350 " <num> ", iteminfo::no_newline, element.second ) );
3351 }
3352 }
3353
3354 if( !bid->bash_protec.empty() ) {
3355 info.push_back( iteminfo( "DESCRIPTION",
3356 _( "<bold>Bash Protection</bold>: " ),
3358 for( const std::pair< const bodypart_str_id, int > element : sorted_lex( bid->bash_protec ) ) {
3359 info.push_back( iteminfo( "CBM", body_part_name_as_heading( element.first->token, 1 ),
3360 " <num> ", iteminfo::no_newline, element.second ) );
3361 }
3362 }
3363
3364 if( !bid->cut_protec.empty() ) {
3365 info.push_back( iteminfo( "DESCRIPTION",
3366 _( "<bold>Cut Protection</bold>: " ),
3368 for( const std::pair< const bodypart_str_id, int > element : sorted_lex( bid->cut_protec ) ) {
3369 info.push_back( iteminfo( "CBM", body_part_name_as_heading( element.first->token, 1 ),
3370 " <num> ", iteminfo::no_newline, element.second ) );
3371 }
3372 }
3373
3374 if( !bid->bullet_protec.empty() ) {
3375 info.push_back( iteminfo( "DESCRIPTION", _( "<bold>Ballistic Protection</bold>: " ),
3377 for( const auto &element : bid->bullet_protec ) {
3378 info.push_back( iteminfo( "CBM", body_part_name_as_heading( element.first->token, 1 ),
3379 " <num> ", iteminfo::no_newline, element.second ) );
3380 }
3381 }
3382
3383 if( !bid->stat_bonus.empty() ) {
3384 info.push_back( iteminfo( "DESCRIPTION", _( "<bold>Stat Bonus</bold>: " ),
3386 for( const auto &element : bid->stat_bonus ) {
3387 info.push_back( iteminfo( "CBM", get_stat_name( element.first ), " <num> ",
3388 iteminfo::no_newline, element.second ) );
3389 }
3390 }
3391
3392 const units::mass weight_bonus = bid->weight_capacity_bonus;
3393 const float weight_modif = bid->weight_capacity_modifier;
3394 if( weight_modif != 1 ) {
3395 std::string modifier;
3396 if( weight_modif < 1 ) {
3397 modifier = "<num><bad>x</bad>";
3398 } else {
3399 modifier = "<num><color_light_green>x</color>";
3400 }
3401 info.push_back( iteminfo( "CBM",
3402 _( "<bold>Weight capacity modifier</bold>: " ), modifier,
3404 weight_modif ) );
3405 }
3406 if( weight_bonus != 0_gram ) {
3407 std::string bonus;
3408 if( weight_bonus < 0_gram ) {
3409 bonus = string_format( "<num> <bad>%s</bad>", weight_units() );
3410 } else {
3411 bonus = string_format( "<num> <color_light_green>%s</color>", weight_units() );
3412 }
3413 info.push_back( iteminfo( "CBM", _( "<bold>Weight capacity bonus</bold>: " ), bonus,
3415 convert_weight( weight_bonus ) ) );
3416 }
3417}
std::string list_occupied_bps(const bionic_id &bio_id, const std::string &intro, const bool each_bp_on_new_line)
Definition: bionics.cpp:2549
std::string body_part_name_as_heading(body_part bp, int number)
Returns the name of the body parts in a context where the name is used as a heading or title e....
Definition: bodypart.cpp:343
std::string get_stat_name(character_stat Stat)
Get translated name of a stat.
Definition: character.cpp:7755
bool is_bionic() const
Definition: item.cpp:6578
std::map< bodypart_str_id, int > cut_protec
Amount of cut protection offered by this bionic.
Definition: bionics.h:88
units::energy capacity
Power bank size.
Definition: bionics.h:49
bool activated
Is true if a bionic is an active instead of a passive bionic.
Definition: bionics.h:53
std::map< character_stat, int > stat_bonus
Map of stats and their corresponding bonuses passively granted by a bionic.
Definition: bionics.h:63
std::vector< itype_id > fuel_opts
Fuel types that can be used by this bionic.
Definition: bionics.h:67
float weight_capacity_modifier
Factor modifiying weight capacity.
Definition: bionics.h:59
units::mass weight_capacity_bonus
Bonus to weight capacity.
Definition: bionics.h:61
std::map< bodypart_str_id, int > encumbrance
Body part encumbered by this bionic, mapped to the amount of encumbrance caused.
Definition: bionics.h:99
std::map< bodypart_str_id, int > bullet_protec
Amount of bullet protection offered by this bionic.
Definition: bionics.h:90
std::map< bodypart_str_id, int > bash_protec
Amount of bash protection offered by this bionic.
Definition: bionics.h:86
std::map< bodypart_str_id, int > env_protec
Amount of environemental protection offered by this bionic.
Definition: bionics.h:84
cata::value_ptr< islot_bionic > bionic
Definition: itype.h:834
const char * vgettext(const char *msgid, const char *msgid_plural, size_t n)

References _, bionic_data::activated, bionic_data::bash_protec, itype::bionic, body_part_name_as_heading(), bionic_data::bullet_protec, bionic_data::capacity, convert_weight(), bionic_data::cut_protec, DESCRIPTION_CBM_SLOTS, bionic_data::encumbrance, enumerate_as_string(), bionic_data::env_protec, bionic_data::fuel_opts, get_stat_name(), info(), insert_separation_line(), is_bionic(), iteminfo::is_decimal, list_occupied_bps(), iteminfo::no_newline, sorted_lex(), bionic_data::stat_bonus, string_format(), iteminfo_query::test(), units::to_joule(), type, vgettext(), bionic_data::weight_capacity_bonus, bionic_data::weight_capacity_modifier, and weight_units().

Referenced by final_info().

◆ birthday()

◆ bonus_from_enchantments()

double item::bonus_from_enchantments ( const Character owner,
double  base,
enchant_vals::mod  value,
bool  round = false 
) const

Calculate bonus from enchantments that affect this item only.

Definition at line 7013 of file item.cpp.

7015{
7016 double add = 0.0;
7017 double mul = 0.0;
7018 for( const enchantment &ench : get_enchantments() ) {
7019 if( ench.is_active( owner, *this ) ) {
7020 add += ench.get_value_add( value );
7021 mul += ench.get_value_multiply( value );
7022 }
7023 }
7024 // TODO: this part duplicates enchantment::calc_bonus()
7025 double ret = add + base * mul;
7026 if( round ) {
7027 ret = trunc( ret );
7028 }
7029 return ret;
7030}
const std::vector< enchantment > & get_enchantments() const
Definition: item.cpp:7004
type add(type dir1, type dir2)
Returns a sum of two numbers.
Definition: overmap.cpp:4206

References om_direction::add(), get_enchantments(), owner, and cata::hash64_detail::ret.

Referenced by item_armor_enchantment_adjust().

◆ bonus_from_enchantments_wielded()

double item::bonus_from_enchantments_wielded ( double  base,
enchant_vals::mod  value,
bool  round = false 
) const

Calculate bonus from enchantments that affect this item only, assume it's wielded and all enchantments' conditions are satisfied.

Definition at line 7032 of file item.cpp.

7034{
7035 double add = 0.0;
7036 double mul = 0.0;
7037 for( const enchantment &ench : get_enchantments() ) {
7038 if( ench.is_active_when_wielded() ) {
7039 add += ench.get_value_add( value );
7040 mul += ench.get_value_multiply( value );
7041 }
7042 }
7043 // TODO: this part duplicates enchantment::calc_bonus()
7044 double ret = add + base * mul;
7045 if( round ) {
7046 ret = trunc( ret );
7047 }
7048 return ret;
7049}

References om_direction::add(), get_enchantments(), and cata::hash64_detail::ret.

Referenced by attack_cost(), and damage_melee().

◆ book_info()

void item::book_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 2918 of file item.cpp.

2920{
2921 if( !is_book() ) {
2922 return;
2923 }
2924
2925 Character &character = get_player_character();
2926
2928 const islot_book &book = *type->book;
2929 // Some things about a book you CAN tell by it's cover.
2930 if( !book.skill && !type->can_use( "MA_MANUAL" ) && parts->test( iteminfo_parts::BOOK_SUMMARY ) ) {
2931 info.push_back( iteminfo( "BOOK", _( "Just for fun." ) ) );
2932 }
2933 if( type->can_use( "MA_MANUAL" ) && parts->test( iteminfo_parts::BOOK_SUMMARY ) ) {
2934 info.push_back( iteminfo( "BOOK",
2935 _( "Some sort of <info>martial arts training "
2936 "manual</info>." ) ) );
2937 const matype_id style_to_learn = martial_art_learned_from( *type );
2938 info.push_back( iteminfo( "BOOK",
2939 string_format( _( "You can learn <info>%s</info> style "
2940 "from it." ), style_to_learn->name ) ) );
2941 info.push_back( iteminfo( "BOOK",
2942 string_format( _( "This fighting style is <info>%s</info> "
2943 "to learn." ),
2944 martialart_difficulty( style_to_learn ) ) ) );
2945 info.push_back( iteminfo( "BOOK",
2946 string_format( _( "It'd be easier to master if you'd have "
2947 "skill expertise in <info>%s</info>." ),
2948 style_to_learn->primary_skill->name() ) ) );
2949 }
2950 if( book.req == 0 && parts->test( iteminfo_parts::BOOK_REQUIREMENTS_BEGINNER ) ) {
2951 info.push_back( iteminfo( "BOOK", _( "It can be <info>understood by "
2952 "beginners</info>." ) ) );
2953 }
2954 avatar &you = get_avatar();
2955 if( !you.has_identified( typeId() ) && parts->test( iteminfo_parts::BOOK_UNREAD ) ) {
2956 info.push_back( iteminfo( "BOOK",
2957 _( "You have <info>never read</info> this book." ) ) );
2958 }
2959 if( book.skill ) {
2960 const SkillLevel &skill = you.get_skill_level_object( book.skill );
2961 if( skill.can_train() && parts->test( iteminfo_parts::BOOK_SKILLRANGE_MAX ) ) {
2962 const std::string skill_name = book.skill->name();
2963 std::string fmt = string_format( _( "Can bring your <info>%s skill to</info> "
2964 "<num>." ), skill_name );
2965 info.push_back( iteminfo( "BOOK", "", fmt, iteminfo::no_flags, book.level ) );
2966 fmt = string_format( _( "Your current <stat>%s skill</stat> is <num>." ),
2967 skill_name );
2968 info.push_back( iteminfo( "BOOK", "", fmt, iteminfo::no_flags, skill.level() ) );
2969 }
2970
2971 if( book.req != 0 && parts->test( iteminfo_parts::BOOK_SKILLRANGE_MIN ) ) {
2972 const std::string fmt = string_format(
2973 _( "<info>Requires %s level</info> <num> to "
2974 "understand." ), book.skill.obj().name() );
2975 info.push_back( iteminfo( "BOOK", "", fmt,
2977 }
2978 }
2979
2980 if( book.intel != 0 && parts->test( iteminfo_parts::BOOK_REQUIREMENTS_INT ) ) {
2981 info.push_back( iteminfo( "BOOK", "",
2982 _( "Requires <info>intelligence of</info> <num> to easily "
2983 "read." ), iteminfo::lower_is_better, book.intel ) );
2984 }
2985 if( character_funcs::get_book_fun_for( character, *this ) != 0 &&
2987 info.push_back( iteminfo( "BOOK", "",
2988 _( "Reading this book affects your morale by <num>" ),
2990 }
2992 std::string fmt = vgettext(
2993 "A chapter of this book takes <num> <info>minute to "
2994 "read</info>.",
2995 "A chapter of this book takes <num> <info>minutes to "
2996 "read</info>.", book.time );
2997 if( type->use_methods.count( "MA_MANUAL" ) ) {
2998 fmt = vgettext(
2999 "<info>A training session</info> with this book takes "
3000 "<num> <info>minute</info>.",
3001 "<info>A training session</info> with this book takes "
3002 "<num> <info>minutes</info>.", book.time );
3003 }
3004 info.push_back( iteminfo( "BOOK", "", fmt,
3006 }
3007
3008 if( book.chapters > 0 && parts->test( iteminfo_parts::BOOK_NUMUNREADCHAPTERS ) ) {
3009 const int unread = get_remaining_chapters( you );
3010 std::string fmt = vgettext( "This book has <num> <info>unread chapter</info>.",
3011 "This book has <num> <info>unread chapters</info>.",
3012 unread );
3013 info.push_back( iteminfo( "BOOK", "", fmt, iteminfo::no_flags, unread ) );
3014 }
3015
3016 std::vector<std::string> recipe_list;
3017 for( const islot_book::recipe_with_description_t &elem : book.recipes ) {
3018 const bool knows_it = you.knows_recipe( elem.recipe );
3019 const bool can_learn = you.get_skill_level( elem.recipe->skill_used ) >= elem.skill_level;
3020 // If the player knows it, they recognize it even if it's not clearly stated.
3021 if( elem.is_hidden() && !knows_it ) {
3022 continue;
3023 }
3024 if( knows_it ) {
3025 // In case the recipe is known, but has a different name in the book, use the
3026 // real name to avoid confusing the player.
3027 const std::string name = elem.recipe->result_name();
3028 recipe_list.push_back( "<bold>" + name + "</bold>" );
3029 } else if( !can_learn ) {
3030 recipe_list.push_back( "<color_brown>" + elem.name + "</color>" );
3031 } else {
3032 recipe_list.push_back( "<dark>" + elem.name + "</dark>" );
3033 }
3034 }
3035
3036 if( !recipe_list.empty() && parts->test( iteminfo_parts::DESCRIPTION_BOOK_RECIPES ) ) {
3037 std::string recipe_line =
3038 string_format( vgettext( "This book contains %1$d crafting recipe: %2$s",
3039 "This book contains %1$d crafting recipes: %2$s",
3040 recipe_list.size() ),
3041 recipe_list.size(), enumerate_as_string( recipe_list ) );
3042
3044 info.push_back( iteminfo( "DESCRIPTION", recipe_line ) );
3045 }
3046
3047 if( recipe_list.size() != book.recipes.size() &&
3049 info.push_back( iteminfo( "DESCRIPTION",
3050 _( "It might help you figuring out some <good>more "
3051 "recipes</good>." ) ) );
3052 }
3053}
Character & get_player_character()
Definition: character.cpp:403
SkillLevel & get_skill_level_object(const skill_id &ident)
Definition: character.cpp:3345
bool knows_recipe(const recipe *rec) const
int get_skill_level(const skill_id &ident) const
Definition: character.cpp:3350
int level() const
Definition: skill.h:125
bool can_train() const
Definition: skill.cpp:311
std::string name() const
Definition: skill.h:68
bool has_identified(const itype_id &item_id) const
Note that we've read a book at least once.
Definition: avatar.cpp:954
bool is_book() const
Definition: item.cpp:6735
int get_remaining_chapters(const Character &ch) const
Get the number of unread chapters.
Definition: item.cpp:7123
translation name
Definition: martialarts.h:270
skill_id primary_skill
Definition: martialarts.h:274
std::string result_name() const
Definition: recipe.cpp:615
skill_id skill_used
Definition: recipe.h:109
@ BOOK_REQUIREMENTS_BEGINNER
@ DESCRIPTION_BOOK_ADDITIONAL_RECIPES
std::string martialart_difficulty(const matype_id &mstyle)
matype_id martial_art_learned_from(const itype &type)
Definition: martialarts.cpp:90
int get_book_fun_for(const Character &ch, const item &book)
Returns enjoyability value of a book for given character.
What recipes can be learned from this book.
Definition: itype.h:360
std::string name
The name for the recipe as it appears in the book.
Definition: itype.h:372
int skill_level
The skill level required to learn the recipe.
Definition: itype.h:368
const class recipe * recipe
The recipe that can be learned (never null).
Definition: itype.h:364
int level
The skill level the book provides.
Definition: itype.h:335
int intel
Intelligence required to read it.
Definition: itype.h:347
skill_id skill
Which skill it upgrades, if any.
Definition: itype.h:327
int req
The skill level required to understand it.
Definition: itype.h:339
recipe_list_t recipes
Definition: itype.h:385
int time
How long in minutes it takes to read.
Definition: itype.h:352
int chapters
Fun books have chapters; after all are read, the book is less fun.
Definition: itype.h:356
@ show_plus
Use a + sign for positive values.
Definition: item.h:149
cata::value_ptr< islot_book > book
Definition: itype.h:825
std::map< std::string, use_function > use_methods
Actions an instance can perform (if any) indexed by action type.
Definition: itype.h:896

References _, itype::book, BOOK_MORALECHANGE, BOOK_NUMUNREADCHAPTERS, BOOK_REQUIREMENTS_BEGINNER, BOOK_REQUIREMENTS_INT, BOOK_SKILLRANGE_MAX, BOOK_SKILLRANGE_MIN, BOOK_SUMMARY, BOOK_TIMEPERCHAPTER, BOOK_UNREAD, SkillLevel::can_train(), itype::can_use(), islot_book::chapters, DESCRIPTION_BOOK_ADDITIONAL_RECIPES, DESCRIPTION_BOOK_RECIPES, enumerate_as_string(), get_avatar(), character_funcs::get_book_fun_for(), get_player_character(), get_remaining_chapters(), Character::get_skill_level(), Character::get_skill_level_object(), avatar::has_identified(), info(), insert_separation_line(), islot_book::intel, is_book(), islot_book::recipe_with_description_t::is_hidden(), Character::knows_recipe(), islot_book::level, SkillLevel::level(), iteminfo::lower_is_better, martial_art_learned_from(), martialart_difficulty(), islot_book::recipe_with_description_t::name, martialart::name, Skill::name(), om_direction::name(), iteminfo::no_flags, string_id< T >::obj(), martialart::primary_skill, islot_book::recipe_with_description_t::recipe, islot_book::recipes, islot_book::req, recipe::result_name(), iteminfo::show_plus, islot_book::skill, islot_book::recipe_with_description_t::skill_level, recipe::skill_used, string_format(), iteminfo_query::test(), islot_book::time, type, typeId(), itype::use_methods, and vgettext().

Referenced by info().

◆ brewing_results()

const std::vector< itype_id > & item::brewing_results ( ) const

The results of fermenting this item.

Definition at line 5977 of file item.cpp.

5978{
5979 static const std::vector<itype_id> nulresult{};
5980 return is_brewable() ? type->brewable->results : nulresult;
5981}
bool is_brewable() const
Definition: item.cpp:6629
cata::value_ptr< islot_brewable > brewable
Definition: itype.h:822

References itype::brewable, is_brewable(), and type.

Referenced by final_info(), and iexamine::fvat_full().

◆ brewing_time()

time_duration item::brewing_time ( ) const

Time for this item to be fully fermented.

Definition at line 5972 of file item.cpp.

5973{
5974 return is_brewable() ? type->brewable->time : 0_turns;
5975}

References itype::brewable, is_brewable(), and type.

Referenced by final_info(), and iexamine::fvat_full().

◆ bullet_resist()

int item::bullet_resist ( bool  to_self = false) const

Definition at line 6124 of file item.cpp.

6125{
6126 if( is_null() ) {
6127 return 0;
6128 }
6129
6130 const int base_thickness = get_thickness();
6131 float resist = 0;
6133 int eff_thickness = 1;
6134
6135 // base resistance
6136 // Don't give reinforced items +armor, just more resistance to ripping
6137 const int dmg = damage_level( 4 );
6138 const int eff_damage = to_self ? std::min( dmg, 0 ) : std::max( dmg, 0 );
6139 eff_thickness = std::max( 1, base_thickness - eff_damage );
6140
6141 const std::vector<const material_type *> mat_types = made_of_types();
6142 if( !mat_types.empty() ) {
6143 for( const material_type *mat : mat_types ) {
6144 resist += mat->bullet_resist();
6145 }
6146 // Average based on number of materials.
6147 resist /= mat_types.size();
6148 }
6149
6150 return std::lround( ( resist * eff_thickness ) + mod );
6151}
@ clothing_mod_type_bullet
Definition: clothing_mod.h:21

References clothing_mod_type_bullet, damage_level(), get_clothing_mod_val(), get_thickness(), is_null(), and made_of_types().

Referenced by armor_inventory_preset::armor_inventory_preset(), armor_protection_info(), anonymous_namespace{armor_layers.cpp}::clothing_protection(), damage_resist(), and sew_advanced_actor::use().

◆ burn()

bool item::burn ( fire_data frd)

Burns the item.

Returns true if the item was destroyed.

Definition at line 8301 of file item.cpp.

8302{
8303 float burn_added = simulate_burn( frd );
8304
8305 if( burn_added <= 0 ) {
8306 return false;
8307 }
8308
8309 if( count_by_charges() ) {
8310 if( type->volume == 0_ml ) {
8311 charges = 0;
8312 } else {
8314 ( 3.0 * type->volume ) );
8315 }
8316
8317 return charges <= 0;
8318 }
8319
8320 if( is_corpse() ) {
8321 const mtype *mt = get_mtype();
8322 if( active && mt != nullptr && burnt + burn_added > mt->hp &&
8323 !mt->burn_into.is_null() && mt->burn_into.is_valid() ) {
8324 corpse = &get_mtype()->burn_into.obj();
8325 // Delay rezing
8326 set_age( 0_turns );
8327 burnt = 0;
8328 return false;
8329 }
8330 }
8331
8332 burnt += roll_remainder( burn_added );
8333
8334 const int vol = base_volume() / units::legacy_volume_factor;
8335 return burnt >= vol * 3;
8336}
units::volume base_volume() const
Simplified, faster volume check for when processing time is important and exact volume is not.
Definition: item.cpp:5102
float simulate_burn(fire_data &frd) const
Calculate all burning calculations, but don't actually apply them to item.
Definition: item.cpp:8248
const mtype * get_mtype() const
Definition: item.cpp:6651
void set_age(const time_duration &age)
Definition: item.cpp:10040
bool is_valid() const
Returns whether this id is valid, that means whether it refers to an existing object.
Definition: achievement.cpp:70
static constexpr volume legacy_volume_factor
Definition: units_volume.h:50
int roll_remainder(double value)
Definition: rng.cpp:96
Definition: mtype.h:208
mtype_id burn_into
Definition: mtype.h:331
int hp
Definition: mtype.h:270

References active, base_volume(), mtype::burn_into, burnt, charges, corpse, count_by_charges(), get_mtype(), mtype::hp, is_corpse(), string_id< T >::is_null(), string_id< T >::is_valid(), units::legacy_volume_factor, string_id< T >::obj(), roll_remainder(), set_age(), simulate_burn(), itype::stack_size, type, and itype::volume.

Referenced by Character::absorb_hit().

◆ calc_rot()

time_duration item::calc_rot ( time_point  time,
int  temp 
) const

Returns rot of the item since last rot calculation.

This function should not be called directly. since it does not have all the needed checks or temperature calculations. If you need to calc rot of item call process_rot instead.

Parameters
timeTime point to which rot is calculated
tempTemperature at which the rot is calculated

Definition at line 5677 of file item.cpp.

5678{
5679 // Avoid needlessly calculating already rotten things. Corpses should
5680 // always rot away and food rots away at twice the shelf life. If the food
5681 // is in a sealed container they won't rot away, this avoids needlessly
5682 // calculating their rot in that case.
5683 if( !is_corpse() && get_relative_rot() > 2.0 ) {
5684 return time_duration::from_seconds( 0 );
5685 }
5686
5687 // rot modifier
5688 float factor = 1.0;
5689 if( is_corpse() && has_flag( flag_FIELD_DRESS ) ) {
5690 factor = 0.75;
5691 }
5692
5694 // simulation of different age of food at the start of the game and good/bad storage
5695 // conditions by applying starting variation bonus/penalty of +/- 20% of base shelf-life
5696 // positive = food was produced some time before calendar::start and/or bad storage
5697 // negative = food was stored in good conditions before calendar::start
5699 time_duration spoil_variation = get_shelf_life() * 0.2f;
5700 added_rot += rng( -spoil_variation, spoil_variation );
5701 }
5702
5703 time_duration time_delta = time - last_rot_check;
5704 added_rot += factor * time_delta / 1_hours * get_hourly_rotpoints_at_temp( temp ) * 1_turns;
5705 return added_rot;
5706}
A duration defined as a number of specific time units.
Definition: calendar.h:180
static constexpr time_duration from_seconds(const T t)
Definition: calendar.h:208
static const std::string flag_FIELD_DRESS("FIELD_DRESS")
int get_hourly_rotpoints_at_temp(const int temp)
Get the hourly rot for a given temperature from the precomputed table.
Definition: item.cpp:5661
@ time
Recharges slowly with time.

References flag_FIELD_DRESS(), time_duration::from_seconds(), get_hourly_rotpoints_at_temp(), get_relative_rot(), get_shelf_life(), has_flag(), is_corpse(), last_rot_check, rng(), calendar::start_of_cataclysm, and time.

Referenced by process_rot().

◆ can_contain() [1/2]

bool item::can_contain ( const item it) const

Can this item have given item/itype as content?

For example, airtight for gas, acidproof for acid etc.

Definition at line 7056 of file item.cpp.

7057{
7058 // TODO: Volume check
7059 return can_contain( *it.type );
7060}
bool can_contain(const item &it) const
Can this item have given item/itype as content?
Definition: item.cpp:7056

References can_contain(), and type.

Referenced by can_contain().

◆ can_contain() [2/2]

bool item::can_contain ( const itype tp) const

Definition at line 7062 of file item.cpp.

7063{
7064 if( !type->container ) {
7065 // TODO: Tools etc.
7066 return false;
7067 }
7068
7069 if( tp.phase == LIQUID && !type->container->watertight ) {
7070 return false;
7071 }
7072
7073 // TODO: Acid in waterskins
7074 return true;
7075}
@ LIQUID
Definition: enums.h:175
phase_id phase
Definition: itype.h:913

References itype::container, LIQUID, itype::phase, and type.

◆ can_holster()

bool item::can_holster ( const item obj,
bool  ignore = false 
) const

Checks if item is a holster and currently capable of storing obj.

Parameters
objobject that we want to holster
ignoreonly check item is compatible and ignore any existing contents

Definition at line 8894 of file item.cpp.

8895{
8896 if( !type->can_use( "holster" ) ) {
8897 return false; // item is not a holster
8898 }
8899
8900 const holster_actor *ptr = dynamic_cast<const holster_actor *>
8901 ( type->get_use( "holster" )->get_actor_ptr() );
8902 if( !ptr->can_holster( obj ) ) {
8903 return false; // item is not a suitable holster for obj
8904 }
8905
8906 if( !ignore && static_cast<int>( contents.num_item_stacks() ) >= ptr->multi ) {
8907 return false; // item is already full
8908 }
8909
8910 return true;
8911}
Holster a weapon.
Definition: iuse_actor.h:842
size_t num_item_stacks() const
returns the number of items stacks in contents each item that is not count_by_charges,...
const void * ptr(const T *p)
\rst Converts p to const void* for pointer formatting.

References itype::can_use(), contents, use_function::get_actor_ptr(), itype::get_use(), item_contents::num_item_stacks(), ptr(), and type.

◆ can_reload_with() [1/2]

bool item::can_reload_with ( const ammotype ammo) const

Returns true if this item can be reloaded with specified ammo type, ignoring currently loaded ammo.

Definition at line 6887 of file item.cpp.

6888{
6889 return is_reloadable_helper( ammo->default_ammotype(), false );
6890}
bool is_reloadable_helper(const itype_id &ammo, bool now) const
Helper for checking reloadability.
Definition: item.cpp:6902

References ammunition_type::default_ammotype(), and is_reloadable_helper().

Referenced by favorite_ammo_or_select(), avatar_funcs::gunmod_add(), and aim_activity_actor::load_RAS_weapon().

◆ can_reload_with() [2/2]

bool item::can_reload_with ( const itype_id ammo) const

Returns true if this item can be reloaded with specified ammo item, ignoring currently loaded ammo.

Definition at line 6892 of file item.cpp.

6893{
6894 return is_reloadable_helper( ammo, false );
6895}

References is_reloadable_helper().

◆ can_revive()

bool item::can_revive ( ) const

Whether this is a corpse that can be revived.

Definition at line 5983 of file item.cpp.

5984{
5985 return is_corpse() && corpse->has_flag( MF_REVIVES ) && damage() < max_damage() &&
5989}
int max_damage() const
Maximum amount of damage to an item (state before destroyed)
Definition: item.cpp:6242
static const std::string flag_QUARTERED("QUARTERED")
static const std::string flag_SKINNED("SKINNED")
static const std::string flag_FIELD_DRESS_FAILED("FIELD_DRESS_FAILED")
static const std::string flag_PULPED("PULPED")
@ MF_REVIVES
Definition: mtype.h:125
bool has_flag(m_flag flag) const
Definition: mtype.cpp:75

References corpse, damage(), flag_FIELD_DRESS(), flag_FIELD_DRESS_FAILED(), flag_PULPED(), flag_QUARTERED(), flag_SKINNED(), has_flag(), mtype::has_flag(), is_corpse(), max_damage(), and MF_REVIVES.

Referenced by active_item_cache::add(), color_in_inventory(), has_rotten_away(), ready_to_revive(), active_item_cache::remove(), basecamp::start_relay_hide_site(), and basecamp::start_setup_hide_site().

◆ can_unload_liquid()

bool item::can_unload_liquid ( ) const

Returns true if not empty if it's liquid, it's not currently frozen in resealable container.

Definition at line 6876 of file item.cpp.

6877{
6878 if( is_container_empty() ) {
6879 return true;
6880 }
6881
6882 const item &cts = contents.front();
6883 bool cts_is_frozen_liquid = cts.made_of( LIQUID ) && cts.made_of( SOLID );
6884 return is_bucket() || !cts_is_frozen_liquid;
6885}
const std::vector< material_id > & made_of() const
The ids of all the materials this is made of.
Definition: item.cpp:6439
bool is_container_empty() const
Whether this item has no contents at all.
Definition: item.cpp:6863
bool is_bucket() const
Definition: item.cpp:6760
@ SOLID
Definition: enums.h:175

References contents, item_contents::front(), is_bucket(), is_container_empty(), LIQUID, made_of(), and SOLID.

Referenced by item_funcs::can_be_unloaded(), iexamine::keg(), and avatar_funcs::unload_item().

◆ casings_count()

int item::casings_count ( ) const

How many spent casings are contained within this item?

Definition at line 8107 of file item.cpp.

8108{
8109 int res = 0;
8110
8111 const_cast<item *>( this )->casings_handle( [&res]( item & ) {
8112 ++res;
8113 return false;
8114 } );
8115
8116 return res;
8117}
void casings_handle(const std::function< bool(item &)> &func)
Apply predicate to each contained spent casing removing it if predicate returns true.
Definition: item.cpp:8119

References casings_handle().

Referenced by item_funcs::can_be_unloaded(), and avatar_funcs::unload_item().

◆ casings_handle()

void item::casings_handle ( const std::function< bool(item &)> &  func)

Apply predicate to each contained spent casing removing it if predicate returns true.

Definition at line 8119 of file item.cpp.

8120{
8121 if( !is_gun() ) {
8122 return;
8123 }
8124
8125 contents.casings_handle( func );
8126}
void casings_handle(const std::function< bool(item &)> &func)

References item_contents::casings_handle(), contents, and is_gun().

Referenced by casings_count(), avatar_funcs::gunmod_remove(), reload(), and avatar_funcs::unload_item().

◆ charges_per_volume()

int item::charges_per_volume ( const units::volume vol) const

Number of (charges of) this item that fit into the given volume.

May return 0 if not even one charge fits into the volume. Only depends on the type of this item not on its current charge count.

For items not counted by charges, this returns vol / this->volume().

Definition at line 868 of file item.cpp.

869{
870 if( count_by_charges() ) {
871 if( type->volume == 0_ml ) {
872 debugmsg( "Item '%s' with zero volume", tname() );
873 return INFINITE_CHARGES;
874 }
875 // Type cast to prevent integer overflow with large volume containers like the cargo
876 // dimension
877 return vol * static_cast<int64_t>( type->stack_size ) / type->volume;
878 } else {
879 units::volume my_volume = volume();
880 if( my_volume == 0_ml ) {
881 debugmsg( "Item '%s' with zero volume", tname() );
882 return INFINITE_CHARGES;
883 }
884 return vol / my_volume;
885 }
886}
static const int INFINITE_CHARGES
Definition: item.h:2168

References count_by_charges(), debugmsg, INFINITE_CHARGES, itype::stack_size, tname(), type, volume(), and itype::volume.

Referenced by item_stack::amount_can_fit(), Character::can_feed_furnace_with(), vehicle_part::consume_energy(), display_name(), Character::feed_furnace_with(), activity_handlers::fill_liquid_do_turn(), Character::get_acquirable_energy(), get_remaining_capacity_for_liquid(), in_container(), Item_factory::migrate_item(), Item_modifier::modify(), vehicle::print_fuel_indicator(), advanced_inventory::query_charges(), and try_fuel_fire().

◆ chip_resistance()

int item::chip_resistance ( bool  worst = false) const

Returns resistance to being damaged by attack against the item itself.

Calculated from item's materials.

Parameters
worstIf this is true, the worst resistance is used. Otherwise the best one.

Definition at line 6218 of file item.cpp.

6219{
6220 int res = worst ? INT_MAX : INT_MIN;
6221 for( const material_type *mat : made_of_types() ) {
6222 const int val = mat->chip_resist();
6223 res = worst ? std::min( res, val ) : std::max( res, val );
6224 }
6225
6226 if( res == INT_MAX || res == INT_MIN ) {
6227 return 2;
6228 }
6229
6230 if( res <= 0 ) {
6231 return 0;
6232 }
6233
6234 return res;
6235}

References made_of_types().

Referenced by Character::handle_melee_wear().

◆ clear_vars()

void item::clear_vars ( )

Removes all item variables.

Definition at line 1089 of file item.cpp.

1090{
1091 item_vars.clear();
1092}

References item_vars.

Referenced by iuse::camera(), einkpc_download_memory_card(), and iuse::einktabletpc().

◆ color()

nc_color item::color ( ) const

Returns the default color of the item (e.g.

itype::color).

Definition at line 4936 of file item.cpp.

4937{
4938 if( is_null() ) {
4939 return c_black;
4940 }
4941 if( is_corpse() ) {
4942 return corpse->color;
4943 }
4944 return type->color;
4945}
#define c_black
Definition: color.h:17
nc_color color
Definition: itype.h:977
nc_color color
Definition: mtype.h:261

References c_black, itype::color, mtype::color, corpse, is_corpse(), is_null(), and type.

Referenced by map::draw_maptile(), Character::pour_into(), and debug_menu::wishitem().

◆ color_in_inventory() [1/2]

nc_color item::color_in_inventory ( ) const

Returns the color of the item depending on usefulness for the player character, e.g.

differently if it its an unread book or a spoiling food item etc. This should only be used for displaying data, it should not affect game play.

Definition at line 4148 of file item.cpp.

4149{
4151}
nc_color color_in_inventory() const
Returns the color of the item depending on usefulness for the player character, e....
Definition: item.cpp:4148

References color_in_inventory(), and get_avatar().

Referenced by color_in_inventory(), colorized_item_name(), inventory_selector_preset::get_color(), read_inventory_preset::get_color(), avatar_funcs::gunmod_add(), game::list_items(), iuse::marloss_seed(), pickup::pick_up(), iuse::seed(), Character::takeoff(), and Character::will_eat().

◆ color_in_inventory() [2/2]

nc_color item::color_in_inventory ( const player p) const

Returns the color of the item depending on usefulness for the passed player, e.g.

differently if it its an unread book or a spoiling food item etc. This should only be used for displaying data, it should not affect game play.

Parameters
for_playerNPC or avatar which would read book.

Definition at line 4153 of file item.cpp.

4154{
4155 // Only item not otherwise colored gets colored as favorite
4157 if( type->can_use( "learn_spell" ) ) {
4158 const use_function *iuse = get_use( "learn_spell" );
4159 const learn_spell_actor *actor_ptr =
4160 static_cast<const learn_spell_actor *>( iuse->get_actor_ptr() );
4161 for( const std::string &spell_id_str : actor_ptr->spells ) {
4162 const spell_id sp_id( spell_id_str );
4163 if( p.magic->knows_spell( sp_id ) && !p.magic->get_spell( sp_id ).is_max_level() ) {
4164 ret = c_yellow;
4165 }
4166 if( !p.magic->knows_spell( sp_id ) && p.magic->can_learn_spell( p, sp_id ) ) {
4167 return c_light_blue;
4168 }
4169 }
4170 } else if( has_flag( flag_WET ) ) {
4171 ret = c_cyan;
4172 } else if( has_flag( flag_LITCIG ) ) {
4173 ret = c_red;
4174 } else if( is_armor() && p.has_trait( trait_WOOLALLERGY ) &&
4175 ( made_of( material_id( "wool" ) ) || has_own_flag( "wooled" ) ) ) {
4176 ret = c_red;
4177 } else if( is_filthy() || has_own_flag( "DIRTY" ) ) {
4178 ret = c_brown;
4179 } else if( is_bionic() ) {
4180 if( !p.has_bionic( type->bionic->id ) ) {
4181 ret = p.bionic_installation_issues( type->bionic->id ).empty() ? c_green : c_red;
4182 } else if( !has_fault( fault_bionic_nonsterile ) ) {
4183 ret = c_dark_gray;
4184 }
4185 } else if( has_flag( flag_LEAK_DAM ) && has_flag( flag_RADIOACTIVE ) && damage() > 0 ) {
4187 } else if( active && !is_food() && !is_food_container() && !is_corpse() ) {
4188 // Active items show up as yellow
4189 ret = c_yellow;
4190 } else if( is_corpse() && can_revive() ) {
4191 // Only reviving corpses are yellow
4192 ret = c_yellow;
4193 } else if( const item *food = get_food() ) {
4194 const bool preserves = type->container && type->container->preserves;
4195
4196 // Give color priority to allergy (allergy > inedible by freeze or other conditions)
4197 // TODO: refactor u.will_eat to let this section handle coloring priority without duplicating code.
4198 if( p.allergy_type( *food ) != morale_type( "morale_null" ) ) {
4199 return c_red;
4200 }
4201
4202 // Default: permafood, drugs
4203 // Brown: rotten (for non-saprophages) or non-rotten (for saprophages)
4204 // Dark gray: inedible
4205 // Red: morale penalty
4206 // Yellow: will rot soon
4207 // Cyan: will rot eventually
4208 const ret_val<edible_rating> rating = p.will_eat( *food );
4209 // TODO: More colors
4210 switch( rating.value() ) {
4213 if( preserves ) {
4214 // Nothing, canned food won't rot
4215 } else if( food->is_going_bad() ) {
4216 ret = c_yellow;
4217 } else if( food->goes_bad() ) {
4218 ret = c_cyan;
4219 }
4220 break;
4223 ret = c_dark_gray;
4224 break;
4228 ret = c_red;
4229 break;
4231 ret = c_brown;
4232 break;
4235 ret = c_pink;
4236 break;
4238 break;
4239 }
4240 } else if( is_gun() ) {
4241 // Guns are green if you are carrying ammo for them
4242 // ltred if you have ammo but no mags
4243 // Gun with integrated mag counts as both
4244 for( const ammotype &at : ammo_types() ) {
4245 // get_ammo finds uncontained ammo, find_ammo finds ammo in magazines
4246 bool has_ammo = !character_funcs::get_ammo_items( p, at ).empty() ||
4247 !character_funcs::find_ammo_items_or_mags( p, *this, false, -1 ).empty();
4248 bool has_mag = magazine_integral() ||
4249 !character_funcs::find_ammo_items_or_mags( p, *this, true, -1 ).empty();
4250 if( has_ammo && has_mag ) {
4251 ret = c_green;
4252 break;
4253 } else if( has_ammo || has_mag ) {
4254 ret = c_light_red;
4255 break;
4256 }
4257 }
4258 } else if( is_ammo() ) {
4259 // Likewise, ammo is green if you have guns that use it
4260 // ltred if you have the gun but no mags
4261 // Gun with integrated mag counts as both
4262 bool has_gun = p.has_item_with( [this]( const item & i ) {
4263 return i.is_gun() && i.ammo_types().count( ammo_type() );
4264 } );
4265 bool has_mag = p.has_item_with( [this]( const item & i ) {
4266 return ( i.is_gun() && i.magazine_integral() && i.ammo_types().count( ammo_type() ) ) ||
4267 ( i.is_magazine() && i.ammo_types().count( ammo_type() ) );
4268 } );
4269 if( has_gun && has_mag ) {
4270 ret = c_green;
4271 } else if( has_gun || has_mag ) {
4272 ret = c_light_red;
4273 }
4274 } else if( is_magazine() ) {
4275 // Magazines are green if you have guns and ammo for them
4276 // ltred if you have one but not the other
4277 bool has_gun = p.has_item_with( [this]( const item & it ) {
4278 return it.is_gun() && it.magazine_compatible().count( typeId() ) > 0;
4279 } );
4280 bool has_ammo = !character_funcs::find_ammo_items_or_mags( p, *this, false, -1 ).empty();
4281 if( has_gun && has_ammo ) {
4282 ret = c_green;
4283 } else if( has_gun || has_ammo ) {
4284 ret = c_light_red;
4285 }
4286 } else if( is_book() ) {
4287 const islot_book &tmp = *type->book;
4288 // Player doesn't actually interested if NPC has identified book yet.
4289 // So we check identification for human avatar.
4290 if( get_avatar().has_identified( typeId() ) ) {
4291 if( tmp.skill && // Book can improve skill: blue
4293 p.get_skill_level( tmp.skill ) >= tmp.req &&
4294 p.get_skill_level( tmp.skill ) < tmp.level ) {
4295 ret = c_light_blue;
4296 } else if( type->can_use( "MA_MANUAL" ) &&
4297 !p.martial_arts_data->has_martialart( martial_art_learned_from( *type ) ) ) {
4298 ret = c_light_blue;
4299 } else if( tmp.skill && // Book can't improve skill right now, but maybe later: pink
4301 p.get_skill_level( tmp.skill ) < tmp.level ) {
4302 ret = c_pink;
4303 } else if( !p.studied_all_recipes(
4304 *type ) ) { // Book can't improve skill anymore, but has more recipes: yellow
4305 ret = c_yellow;
4306 }
4307 } else if( tmp.skill || type->can_use( "MA_MANUAL" ) ) {
4308 // Book can teach you something and hasn't been identified yet
4309 ret = c_red;
4310 } else {
4311 // "just for fun" book that they haven't read yet
4312 ret = c_magenta;
4313 }
4314 }
4315 return ret;
4316}
morale_type allergy_type(const item &food) const
Returns allergy type or MORALE_NULL if not allergic for this character.
pimpl< character_martial_arts > martial_arts_data
Definition: character.h:1588
ret_val< edible_rating > will_eat(const item &food, bool interactive=false) const
Same as can_eat, but takes consequences into account.
bool has_bionic(const bionic_id &b) const
Returns true if the player has the entered bionic id.
Definition: character.cpp:1815
std::map< bodypart_id, int > bionic_installation_issues(const bionic_id &bioid) const
Definition: bionics.cpp:2579
bool has_trait(const trait_id &b) const override
Returns true if the player has the entered trait.
Definition: mutation.cpp:101
pimpl< known_magic > magic
Definition: character.h:1485
bool is_favorite
Definition: item.h:2249
std::set< itype_id > magazine_compatible(bool conversion=true) const
Get compatible magazines (if any) for this item.
Definition: item.cpp:7714
bool has_fault(const fault_id &fault) const
Does this item have the specified fault.
Definition: item.cpp:5319
bool is_filthy() const
Marks the item as filthy, so characters with squeamish trait can't wear it.
Definition: item.cpp:10011
bool is_food_container() const
Definition: item.cpp:6634
const use_function * get_use(const std::string &use_name) const
Returns the pointer to use_function with name use_name assigned to the type of this item or any of it...
Definition: item.cpp:7965
bool can_revive() const
Whether this is a corpse that can be revived.
Definition: item.cpp:5983
bool has_own_flag(const std::string &flag) const
Checks whether item itself has given flag (doesn't check item type or gunmods).
Definition: item.cpp:5324
Learn a spell.
Definition: iuse_actor.h:799
std::vector< std::string > spells
Definition: iuse_actor.h:802
bool studied_all_recipes(const itype &book) const
Definition: player.cpp:265
The class represents a composite return value of an arbitrary function (result).
Definition: ret_val.h:21
T value() const
Definition: ret_val.h:74
bool has_item_with(const std::function< bool(const item &)> &filter) const
Returns true if any item (including those within a container) matches the filter.
Definition: visitable.cpp:105
#define c_white
Definition: color.h:18
#define c_light_gray
Definition: color.h:19
#define c_green
Definition: color.h:22
#define c_light_green
Definition: color.h:28
#define c_magenta
Definition: color.h:25
#define c_brown
Definition: color.h:26
#define c_dark_gray
Definition: color.h:20
#define c_pink
Definition: color.h:31
#define c_yellow
Definition: color.h:32
#define c_cyan
Definition: color.h:24
#define c_light_red
Definition: color.h:27
#define c_red
Definition: color.h:21
static const std::string flag_WET("WET")
static const trait_id trait_WOOLALLERGY("WOOLALLERGY")
static const fault_id fault_bionic_nonsterile("fault_bionic_nonsterile")
static const std::string flag_LEAK_DAM("LEAK_DAM")
static const std::string flag_LITCIG("LITCIG")
static const std::string flag_RADIOACTIVE("RADIOACTIVE")
std::vector< const item * > get_ammo_items(const Character &who, const ammotype &at)
Returns character's items that are ammo and have the matching ammo type.
std::vector< item_location > find_ammo_items_or_mags(const Character &who, const item &obj, bool empty, int radius)
Searches for ammo or magazines that can be used to reload given item.
Definition: iuse.h:25
string_id< material_type > material_id
Definition: type_id.h:95

References active, allergy, Character::allergy_type(), allergy_weak, ammo_type(), ammo_types(), itype::bionic, Character::bionic_installation_issues(), bloated, itype::book, c_brown, c_cyan, c_dark_gray, c_green, c_light_blue, c_light_gray, c_light_green, c_light_red, c_magenta, c_pink, c_red, c_white, c_yellow, can_revive(), SkillLevel::can_train(), itype::can_use(), cannibalism, itype::container, damage(), edible, fault_bionic_nonsterile, character_funcs::find_ammo_items_or_mags(), flag_LEAK_DAM(), flag_LITCIG(), flag_RADIOACTIVE(), flag_WET(), character_funcs::get_ammo_items(), get_avatar(), get_food(), Character::get_skill_level(), Character::get_skill_level_object(), get_use(), Character::has_bionic(), has_fault(), has_flag(), visitable< T >::has_item_with(), has_own_flag(), Character::has_trait(), inedible, inedible_mutation, is_ammo(), is_armor(), is_bionic(), is_book(), is_corpse(), is_favorite, is_filthy(), is_food(), is_food_container(), is_gun(), is_magazine(), islot_book::level, made_of(), magazine_compatible(), magazine_integral(), Character::magic, martial_art_learned_from(), Character::martial_arts_data, nausea, no_tool, islot_book::req, cata::hash64_detail::ret, rotten, islot_book::skill, learn_spell_actor::spells, player::studied_all_recipes(), too_full, trait_WOOLALLERGY, type, typeId(), ret_val< T >::value(), and Character::will_eat().

◆ combat_info()

void item::combat_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3419 of file item.cpp.

3421{
3422 const std::string space = " ";
3423
3424 int dmg_bash = damage_melee( DT_BASH );
3425 int dmg_cut = damage_melee( DT_CUT );
3426 int dmg_stab = damage_melee( DT_STAB );
3427 if( parts->test( iteminfo_parts::BASE_DAMAGE ) ) {
3429 std::string sep;
3430 if( dmg_bash || dmg_cut || dmg_stab ) {
3431 info.push_back( iteminfo( "BASE", _( "<bold>Melee damage</bold>: " ), "", iteminfo::no_newline ) );
3432 }
3433 if( dmg_bash ) {
3434 info.push_back( iteminfo( "BASE", _( "Bash: " ), "", iteminfo::no_newline, dmg_bash ) );
3435 sep = space;
3436 }
3437 if( dmg_cut ) {
3438 info.push_back( iteminfo( "BASE", sep + _( "Cut: " ), "", iteminfo::no_newline, dmg_cut ) );
3439 sep = space;
3440 }
3441 if( dmg_stab ) {
3442 info.push_back( iteminfo( "BASE", sep + _( "Pierce: " ), "", iteminfo::no_newline, dmg_stab ) );
3443 }
3444 }
3445
3446 if( dmg_bash || dmg_cut || dmg_stab ) {
3447 if( parts->test( iteminfo_parts::BASE_TOHIT ) ) {
3448 info.push_back( iteminfo( "BASE", space + _( "To-hit bonus: " ), "",
3450 }
3451
3452 if( parts->test( iteminfo_parts::BASE_MOVES ) ) {
3453 info.push_back( iteminfo( "BASE", _( "Moves per attack: " ), "",
3455 info.emplace_back( "BASE", _( "Typical damage per second:" ), "" );
3456 const std::map<std::string, double> &dps_data = dps( true, false );
3457 std::string sep;
3458 for( const std::pair<const std::string, double> &dps_entry : dps_data ) {
3459 info.emplace_back( "BASE", sep + dps_entry.first + ": ", "",
3461 dps_entry.second );
3462 sep = space;
3463 }
3464 info.emplace_back( "BASE", "" );
3465 }
3466 }
3467
3469 std::set<matec_id> all_techniques = type->techniques;
3470 all_techniques.insert( techniques.begin(), techniques.end() );
3471
3472 if( !all_techniques.empty() ) {
3473 const std::vector<matec_id> all_tec_sorted = sorted_lex( all_techniques );
3475 info.push_back( iteminfo( "DESCRIPTION", _( "<bold>Techniques when wielded</bold>: " ) +
3476 enumerate_as_string( all_tec_sorted.begin(), all_tec_sorted.end(), []( const matec_id & tid ) {
3477 return string_format( "<stat>%s</stat>: <info>%s</info>", _( tid.obj().name ),
3478 _( tid.obj().description ) );
3479 } ) ) );
3480 }
3481 }
3482
3483 avatar &you = get_avatar();
3484 // display which martial arts styles character can use with this weapon
3486 const std::string valid_styles = you.martial_arts_data->enumerate_known_styles( typeId() );
3487 if( !valid_styles.empty() ) {
3489 info.push_back( iteminfo( "DESCRIPTION",
3490 _( "You know how to use this with these martial arts "
3491 "styles: " ) + valid_styles ) );
3492 }
3493 }
3494
3495 if( !is_gunmod() && has_flag( flag_REACH_ATTACK ) &&
3498 if( has_flag( flag_REACH3 ) ) {
3499 info.push_back( iteminfo( "DESCRIPTION",
3500 _( "* This item can be used to make <stat>long reach "
3501 "attacks</stat>." ) ) );
3502 } else {
3503 info.push_back( iteminfo( "DESCRIPTION",
3504 _( "* This item can be used to make <stat>reach "
3505 "attacks</stat>." ) ) );
3506 }
3507 }
3508
3509 if( ( dmg_bash || dmg_cut || dmg_stab || type->m_to_hit > 0 ) || debug_mode ) {
3510 damage_instance non_crit;
3511 you.roll_all_damage( false, non_crit, true, *this );
3512 damage_instance crit;
3513 you.roll_all_damage( true, crit, true, *this );
3514 int attack_cost = you.attack_cost( *this );
3517 info.push_back( iteminfo( "DESCRIPTION", _( "<bold>Average melee damage</bold>:" ) ) );
3518 }
3519 // Chance of critical hit
3521 info.push_back( iteminfo( "DESCRIPTION",
3522 string_format( _( "Critical hit chance <neutral>%d%% - %d%%</neutral>" ),
3523 static_cast<int>( you.crit_chance( 0, 100, *this ) *
3524 100 ),
3525 static_cast<int>( you.crit_chance( 100, 0, *this ) *
3526 100 ) ) ) );
3527 }
3528 // Bash damage
3530 // NOTE: Using "BASE" instead of "DESCRIPTION", so numerical formatting will work
3531 // (output.cpp:format_item_info does not interpolate <num> for DESCRIPTION info)
3532 info.push_back( iteminfo( "BASE", _( "Bashing: " ), "<num>", iteminfo::no_newline,
3533 non_crit.type_damage( DT_BASH ) ) );
3534 info.push_back( iteminfo( "BASE", space + _( "Critical bash: " ), "<num>", iteminfo::no_flags,
3535 crit.type_damage( DT_BASH ) ) );
3536 }
3537 // Cut damage
3538 if( ( non_crit.type_damage( DT_CUT ) > 0.0f || crit.type_damage( DT_CUT ) > 0.0f )
3540
3541 info.push_back( iteminfo( "BASE", _( "Cutting: " ), "<num>", iteminfo::no_newline,
3542 non_crit.type_damage( DT_CUT ) ) );
3543 info.push_back( iteminfo( "BASE", space + _( "Critical cut: " ), "<num>", iteminfo::no_flags,
3544 crit.type_damage( DT_CUT ) ) );
3545 }
3546 // Pierce/stab damage
3547 if( ( non_crit.type_damage( DT_STAB ) > 0.0f || crit.type_damage( DT_STAB ) > 0.0f )
3549
3550 info.push_back( iteminfo( "BASE", _( "Piercing: " ), "<num>", iteminfo::no_newline,
3551 non_crit.type_damage( DT_STAB ) ) );
3552 info.push_back( iteminfo( "BASE", space + _( "Critical pierce: " ), "<num>", iteminfo::no_flags,
3553 crit.type_damage( DT_STAB ) ) );
3554 }
3555 // Moves
3557 info.push_back( iteminfo( "BASE", _( "Moves per attack: " ), "<num>",
3559 }
3561 }
3562}
bool debug_mode
Extended debugging mode, can be toggled during game.
int attack_cost(const item &weap) const
Returns cost (in moves) of attacking with given item (no modifiers, like stuck)
Definition: melee.cpp:2279
double crit_chance(float roll_hit, float target_dodge, const item &weap) const
Returns the chance to critical given a hit roll and target's dodge roll.
Definition: melee.cpp:796
void roll_all_damage(bool crit, damage_instance &di, bool average, const item &weap) const
Adds all 3 types of physical damage to instance.
Definition: melee.cpp:412
int attack_cost() const
Base number of moves (Creature::moves) that a single melee attack with this items takes.
Definition: item.cpp:5207
@ DT_STAB
Definition: damage.h:27
@ DT_BASH
Definition: damage.h:24
@ DT_CUT
Definition: damage.h:25
static const std::string flag_REACH3("REACH3")
static const std::string flag_REACH_ATTACK("REACH_ATTACK")
@ DESCRIPTION_MELEEDMG_PIERCE
@ DESCRIPTION_GUNMOD_ADDREACHATTACK
@ DESCRIPTION_MELEEDMG_MOVES
@ DESCRIPTION_APPLICABLEMARTIALARTS
float type_damage(damage_type dt) const
Definition: damage.cpp:64
int m_to_hit
Definition: itype.h:969
std::set< matec_id > techniques
Definition: itype.h:904

References _, attack_cost(), Character::attack_cost(), BASE_DAMAGE, BASE_MOVES, BASE_TOHIT, Character::crit_chance(), damage_melee(), debug_mode, DESCRIPTION_APPLICABLEMARTIALARTS, DESCRIPTION_GUNMOD_ADDREACHATTACK, DESCRIPTION_MELEEDMG, DESCRIPTION_MELEEDMG_BASH, DESCRIPTION_MELEEDMG_CRIT, DESCRIPTION_MELEEDMG_CUT, DESCRIPTION_MELEEDMG_MOVES, DESCRIPTION_MELEEDMG_PIERCE, DESCRIPTION_TECHNIQUES, dps(), DT_BASH, DT_CUT, DT_STAB, enumerate_as_string(), flag_REACH3(), flag_REACH_ATTACK(), get_avatar(), has_flag(), info(), insert_separation_line(), iteminfo::is_decimal, is_gunmod(), iteminfo::lower_is_better, itype::m_to_hit, Character::martial_arts_data, iteminfo::no_flags, iteminfo::no_newline, Character::roll_all_damage(), iteminfo::show_plus, sorted_lex(), sign::space, string_format(), techniques, itype::techniques, iteminfo_query::test(), type, damage_instance::type_damage(), and typeId().

Referenced by info().

◆ common_ammo_default()

itype_id item::common_ammo_default ( bool  conversion = true) const

Get default ammo for the first ammotype common to an item and its current magazine or "NULL" if none exists.

Parameters
conversionwhether to include the effect of any flags or mods which convert the type
Returns
itype_id of default ammo for the first ammotype common to an item and its current magazine or "NULL" if none exists

Definition at line 7630 of file item.cpp.

7631{
7632 if( !ammo_types( conversion ).empty() ) {
7633 for( const ammotype &at : ammo_types( conversion ) ) {
7634 const item *mag = magazine_current();
7635 if( mag && mag->type->magazine->type.count( at ) ) {
7636 itype_id res = at->default_ammotype();
7637 if( !res.is_empty() ) {
7638 return res;
7639 }
7640 }
7641 }
7642 }
7643 return itype_id::NULL_ID();
7644}

References ammo_types(), string_id< T >::is_empty(), itype::magazine, magazine_current(), string_id< itype >::NULL_ID(), and type.

Referenced by gun_info().

◆ component_info()

void item::component_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3150 of file item.cpp.

3152{
3154 return;
3155 }
3156 if( is_craft() ) {
3157 info.push_back( iteminfo( "DESCRIPTION", string_format( _( "Using: %s" ),
3158 _( components_to_string() ) ) ) );
3159 // Ugly hack warning! Corpses have CBMs as their components
3160 } else if( !is_corpse() ) {
3161 info.push_back( iteminfo( "DESCRIPTION", string_format( _( "Made from: %s" ),
3162 _( components_to_string() ) ) ) );
3163 } else if( get_var( "bionics_scanned_by", -1 ) == get_avatar().getID().get_value() ) {
3164 // TODO: Extract into a more proper place (function in namespace)
3165 std::string bionics_string = enumerate_as_string( components.begin(), components.end(),
3166 []( const item & entry ) -> std::string {
3167 return entry.is_bionic() ? entry.display_name() : "";
3169 info.push_back( iteminfo( "DESCRIPTION", string_format( _( "Contains: %s" ),
3170 bionics_string ) ) );
3171 }
3172}
std::string components_to_string() const
List of all components in printable form, empty if this item has no components.
Definition: item.cpp:8913
@ DESCRIPTION_COMPONENTS_MADEFROM

References _, components, components_to_string(), DESCRIPTION_COMPONENTS_MADEFROM, enumerate_as_string(), get_avatar(), get_var(), info(), is_corpse(), is_craft(), none, string_format(), and iteminfo_query::test().

Referenced by info().

◆ components_to_string()

std::string item::components_to_string ( ) const

List of all components in printable form, empty if this item has no components.

Definition at line 8913 of file item.cpp.

8914{
8915 using t_count_map = std::map<std::string, int>;
8916 t_count_map counts;
8917 for( const item &elem : components ) {
8918 if( !elem.has_flag( flag_BYPRODUCT ) ) {
8919 const std::string name = elem.display_name();
8920 counts[name]++;
8921 }
8922 }
8923 return enumerate_as_string( counts.begin(), counts.end(),
8924 []( const std::pair<std::string, int> &entry ) -> std::string {
8925 if( entry.second != 1 )
8926 {
8927 return string_format( pgettext( "components count", "%d x %s" ), entry.second, entry.first );
8928 } else
8929 {
8930 return entry.first;
8931 }
8933}
static const std::string flag_BYPRODUCT("BYPRODUCT")

References components, enumerate_as_string(), flag_BYPRODUCT(), and om_direction::name().

Referenced by component_info().

◆ conductive()

bool item::conductive ( ) const

Whether the items is conductive.

Definition at line 6504 of file item.cpp.

6505{
6506 if( is_null() ) {
6507 return false;
6508 }
6509
6510 if( has_flag( flag_CONDUCTIVE ) ) {
6511 return true;
6512 }
6513
6514 if( has_flag( flag_NONCONDUCTIVE ) ) {
6515 return false;
6516 }
6517
6518 // If any material has electricity resistance equal to or lower than flesh (1) we are conductive.
6519 const std::vector<const material_type *> &mats = made_of_types();
6520 return std::any_of( mats.begin(), mats.end(), []( const material_type * mt ) {
6521 return mt->elec_resist() <= 1;
6522 } );
6523}
static const std::string flag_CONDUCTIVE("CONDUCTIVE")
static const std::string flag_NONCONDUCTIVE("NONCONDUCTIVE")

References flag_CONDUCTIVE(), flag_NONCONDUCTIVE(), has_flag(), is_null(), and made_of_types().

Referenced by Character::block_hit(), final_info(), and mdefense::zapback().

◆ contain_monster()

int item::contain_monster ( const tripoint target)

Definition at line 9218 of file iuse.cpp.

9219{
9220 const monster *const mon_ptr = g->critter_at<monster>( target );
9221 if( !mon_ptr ) {
9222 return 0;
9223 }
9224 const monster &f = *mon_ptr;
9225
9226 set_var( "contained_json", ::serialize( f ) );
9227 set_var( "contained_name", f.type->nname() );
9228 set_var( "name", string_format( _( "%s holding %s" ), type->nname( 1 ),
9229 f.type->nname() ) );
9230 // Need to add the weight of the empty container because item::weight uses the "weight" variable directly.
9231 set_var( "weight", to_milligram( type->weight + f.get_weight() ) );
9232 g->remove_zombie( f );
9233 return 0;
9234}
void serialize(JsonOut &json) const
const mtype * type
Definition: monster.h:478
units::mass get_weight() const override
Definition: monster.cpp:2740
constexpr value_type to_milligram(const quantity< value_type, mass_in_milligram_tag > &v)
Definition: units_mass.h:62
units::mass weight
Weight of item ( or each stack member )
Definition: itype.h:936
std::string nname(unsigned int quantity) const
Definition: itype.cpp:78
std::string nname(unsigned int quantity=1) const
Definition: mtype.cpp:65

References _, g, monster::get_weight(), itype::nname(), mtype::nname(), serialize(), set_var(), string_format(), units::to_milligram(), type, monster::type, and itype::weight.

Referenced by iuse::capture_monster_act().

◆ container_info()

void item::container_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3055 of file item.cpp.

3057{
3058 if( !is_container() || !parts->test( iteminfo_parts::CONTAINER_DETAILS ) ) {
3059 return;
3060 }
3061
3063 const islot_container &c = *type->container;
3064
3065 std::string container_str = _( "This container " );
3066
3067 if( c.seals ) {
3068 container_str += _( "can be <info>resealed</info>, " );
3069 }
3070 if( c.watertight ) {
3071 container_str += _( "is <info>watertight</info>, " );
3072 }
3073 if( c.preserves ) {
3074 container_str += _( "<good>prevents spoiling</good>, " );
3075 }
3076
3077 container_str += string_format( _( "can store <info>%s %s</info>." ),
3078 format_volume( c.contains ), volume_units_long() );
3079
3080 info.push_back( iteminfo( "CONTAINER", container_str ) );
3081}
bool is_container() const
Whether this is container.
Definition: item.cpp:6745
std::string format_volume(const units::volume &volume)
Convert, round up and format a volume.
Definition: output.cpp:2020
const char * volume_units_long()
Create a units label for a volume value.

References _, c, itype::container, CONTAINER_DETAILS, format_volume(), info(), insert_separation_line(), is_container(), string_format(), iteminfo_query::test(), type, and volume_units_long().

Referenced by info().

◆ contents_info()

void item::contents_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3564 of file item.cpp.

3566{
3568 return;
3569 }
3570 const std::string space = " ";
3571
3572 for( const item *mod : is_gun() ? gunmods() : toolmods() ) {
3573 std::string mod_str;
3574 if( mod->type->gunmod ) {
3575 if( mod->is_irremovable() ) {
3576 mod_str = _( "Integrated mod: " );
3577 } else {
3578 mod_str = _( "Mod: " );
3579 }
3580 mod_str += string_format( "<bold>%s</bold> (%s) ", mod->tname(),
3581 mod->type->gunmod->location.name() );
3582 }
3584 info.emplace_back( "DESCRIPTION", mod_str );
3585 info.emplace_back( "DESCRIPTION", mod->type->description.translated() );
3586 }
3587 bool contents_header = false;
3588 for( const item *contents_item : contents.all_items_top() ) {
3589 if( !contents_item->type->mod ) {
3590 if( !contents_header ) {
3592 info.emplace_back( "DESCRIPTION", _( "<bold>Contents of this item</bold>:" ) );
3593 contents_header = true;
3594 } else {
3595 // Separate items with a blank line
3596 info.emplace_back( "DESCRIPTION", space );
3597 }
3598
3599 const translation &description = contents_item->type->description;
3600
3601 if( contents_item->made_of( LIQUID ) ) {
3602 units::volume contents_volume = contents_item->volume() * batch;
3603 int converted_volume_scale = 0;
3604 const double converted_volume =
3605 round_up( convert_volume( contents_volume.value(),
3606 &converted_volume_scale ), 2 );
3607 info.emplace_back( "DESCRIPTION", contents_item->display_name() );
3609 if( display_mod_source ) {
3610 info.emplace_back( "DESCRIPTION", string_format( _( "<stat>Origin: %s</stat>" ),
3611 enumerate_as_string( contents_item->type->src.begin(),
3612 contents_item->type->src.end(), []( const std::pair<itype_id, mod_id> &content_source ) {
3613 return string_format( "'%s'", content_source.second->name() );
3615 }
3616 if( display_object_ids ) {
3617 info.emplace_back( "DESCRIPTION", colorize(
3618 string_format( "[%s]", contents_item->type->get_id() ),
3619 c_light_blue ) );
3620 }
3621 if( converted_volume_scale != 0 ) {
3623 }
3624 info.emplace_back( "CONTAINER", description + space,
3625 string_format( "<num> %s", volume_units_abbr() ), f,
3626 converted_volume );
3627 } else {
3628 info.emplace_back( "DESCRIPTION", contents_item->display_name() );
3629 if( display_mod_source ) {
3630 info.emplace_back( "DESCRIPTION", string_format( _( "<stat>Origin: %s</stat>" ),
3631 enumerate_as_string( contents_item->type->src.begin(),
3632 contents_item->type->src.end(), []( const std::pair<itype_id, mod_id> &content_source ) {
3633 return string_format( "'%s'", content_source.second->name() );
3635 }
3636 if( display_object_ids ) {
3637 info.emplace_back( "DESCRIPTION", colorize(
3638 string_format( "[%s]", contents_item->type->get_id() ),
3639 c_light_blue ) );
3640 }
3641 info.emplace_back( "DESCRIPTION", description.translated() );
3642 }
3643 }
3644 }
3645}
Class for storing translation context and raw string for deferred translation.
Definition: translations.h:152
constexpr const value_type & value() const
Access the raw dimensionless value.
Definition: units_def.h:44

References _, item_contents::all_items_top(), arrow, c_light_blue, colorize(), contents, convert_volume(), DESCRIPTION_CONTENTS, display_mod_source, display_object_ids, item_contents::empty(), enumerate_as_string(), gunmods(), info(), insert_separation_line(), iteminfo::is_decimal, is_gun(), LIQUID, iteminfo::no_newline, round_up(), sign::space, string_format(), iteminfo_query::test(), toolmods(), translation::translated(), units::quantity< V, U >::value(), and volume_units_abbr().

Referenced by info().

◆ contents_made_of()

bool item::contents_made_of ( phase_id  phase) const

If contents nonempty, return true if item phase is same, else false.

Definition at line 6491 of file item.cpp.

6492{
6493 return !contents.empty() && contents.front().made_of( phase );
6494}

References contents, item_contents::empty(), item_contents::front(), and made_of().

Referenced by character_funcs::find_ammo_helper().

◆ contextualize_skill()

skill_id item::contextualize_skill ( const skill_id id) const

Puts the skill in context of the item.

Definition at line 9996 of file item.cpp.

9997{
9998 if( id->is_contextual_skill() ) {
9999 if( id == skill_weapon ) {
10000 if( is_gun() ) {
10001 return gun_skill();
10002 } else if( is_melee() ) {
10003 return melee_skill();
10004 }
10005 }
10006 }
10007
10008 return id;
10009}
skill_id gun_skill() const
The skill used to operate the gun.
Definition: item.cpp:7213
skill_id melee_skill() const
The most relevant skill used with this melee weapon.
Definition: item.cpp:7221
bool is_melee() const
Is this item an effective melee weapon for any damage type?
Definition: item.cpp:6693
static const skill_id skill_weapon("weapon")
const std::string id
Definition: basecamp.h:87

References gun_skill(), base_camps::id, is_gun(), is_melee(), melee_skill(), and skill_weapon.

Referenced by Character::enumerate_unmet_requirements(), and SkillLevelMap::get_skill_level().

◆ convert()

◆ corpse_volume()

units::volume item::corpse_volume ( const mtype corpse) const

Volume check for corpses, helper for base_volume().

Definition at line 5080 of file item.cpp.

5081{
5083 if( has_flag( flag_QUARTERED ) ) {
5084 corpse_volume /= 4;
5085 }
5087 corpse_volume *= 0.75;
5088 }
5089 if( has_flag( flag_GIBBED ) ) {
5090 corpse_volume *= 0.85;
5091 }
5092 if( has_flag( flag_SKINNED ) ) {
5093 corpse_volume *= 0.85;
5094 }
5095 if( corpse_volume > 0_ml ) {
5096 return corpse_volume;
5097 }
5098 debugmsg( "invalid monster volume for corpse" );
5099 return 0_ml;
5100}
static const std::string flag_GIBBED("GIBBED")
units::volume volume
Definition: mtype.h:263

References corpse, corpse_volume(), debugmsg, flag_FIELD_DRESS(), flag_FIELD_DRESS_FAILED(), flag_GIBBED(), flag_QUARTERED(), flag_SKINNED(), has_flag(), and mtype::volume.

Referenced by base_volume(), corpse_volume(), and volume().

◆ count()

◆ count_by_charges() [1/2]

bool item::count_by_charges ( ) const

Definition at line 6031 of file item.cpp.

6032{
6033 return type->count_by_charges();
6034}

References itype::count_by_charges(), and type.

Referenced by activity_on_turn_wear(), vehicle::add_charges(), vehicle::add_item(), map::add_item_or_charges(), item_stack::amount_can_fit(), base_volume(), basic_info(), burn(), Character::can_eat(), repair_item_actor::can_repair_target(), charges_of_internal(), charges_per_volume(), craft_command::check_item_components_missing(), complete_craft(), crafting::complete_disassemble(), player::consume_items(), count(), craft_has_charges(), recipe::create_byproducts(), recipe::create_results(), display_name(), display_stacked_with(), move_items_activity_actor::do_turn(), throw_activity_actor::do_turn(), mattack::eat_food(), farm_action(), Character::feed_furnace_with(), fetch_activity(), talk_function::field_harvest(), talk_function::field_plant(), iuse_transform::finalize(), emit_actor::finalize(), for_each_item_in_both(), Character::get_acquirable_energy(), recipe::get_consistency_error(), requirement_data::get_folded_list(), iexamine::get_harvest_items(), monexamine::give_items_to(), repair_item_actor::handle_components(), item_comp::has(), talk_function::individual_mission(), io(), repair_inventory_preset::is_shown(), merge_charges(), to_cbc_migration::migration_required(), mod_charges(), mod_damage(), Item_modifier::modify(), advanced_inventory::move_all_items(), move_item(), npc_throw(), pickup::obtain_and_tokenize_items(), pick_one_up(), pickup::pick_up(), activity_handlers::plant_seed_finish(), price(), advanced_inventory::query_charges(), vehicle::reload_seeds(), player::select_item_component(), talk_effect_fun_t::set_u_buy_item(), talk_effect_fun_t::set_u_sell_item(), simulate_burn(), spell_effect::spawn_ethereal_item(), split(), stacks_with(), Character::throw_range(), ranged::throwing_dispersion(), npc_trading::trade(), try_consume(), units_remaining(), units_sufficient(), inventory::update_quality_cache(), use_charges(), volume(), weight(), Character::weight_carried_reduced_by(), and debug_menu::wishitem().

◆ count_by_charges() [2/2]

bool item::count_by_charges ( const itype_id id)
static

Whether the item is counted by charges, this is a static wrapper around count_by_charges, that does not need an items instance.

Definition at line 9957 of file item.cpp.

9958{
9959 return id->count_by_charges();
9960}

◆ covers() [1/2]

◆ covers() [2/2]

bool item::covers ( const bodypart_id bp) const

Definition at line 752 of file item.cpp.

753{
754 return get_covered_body_parts().test( bp->token );
755}
bool test(const body_part &bp) const
Definition: bodypart.h:253

References get_covered_body_parts(), and body_part_set::test().

◆ craft_has_charges()

bool item::craft_has_charges ( )

Definition at line 6041 of file item.cpp.

6042{
6043 if( count_by_charges() ) {
6044 return true;
6045 } else if( ammo_types().empty() ) {
6046 return true;
6047 }
6048
6049 return false;
6050}

References ammo_types(), and count_by_charges().

Referenced by crafting::complete_disassemble(), and recipe::create_byproducts().

◆ cut_resist()

int item::cut_resist ( bool  to_self = false) const

Definition at line 6085 of file item.cpp.

6086{
6087 if( is_null() ) {
6088 return 0;
6089 }
6090
6091 const int base_thickness = get_thickness();
6092 float resist = 0;
6094 int eff_thickness = 1;
6095
6096 // base resistance
6097 // Don't give reinforced items +armor, just more resistance to ripping
6098 const int dmg = damage_level( 4 );
6099 const int eff_damage = to_self ? std::min( dmg, 0 ) : std::max( dmg, 0 );
6100 eff_thickness = std::max( 1, base_thickness - eff_damage );
6101
6102 const std::vector<const material_type *> mat_types = made_of_types();
6103 if( !mat_types.empty() ) {
6104 for( const material_type *mat : mat_types ) {
6105 resist += mat->cut_resist();
6106 }
6107 // Average based on number of materials.
6108 resist /= mat_types.size();
6109 }
6110
6111 return std::lround( ( resist * eff_thickness ) + mod );
6112}
@ clothing_mod_type_cut
Definition: clothing_mod.h:20

References clothing_mod_type_cut, damage_level(), get_clothing_mod_val(), get_thickness(), is_null(), and made_of_types().

Referenced by armor_inventory_preset::armor_inventory_preset(), armor_protection_info(), anonymous_namespace{armor_layers.cpp}::clothing_protection(), damage_resist(), stab_resist(), and sew_advanced_actor::use().

◆ damage()

◆ damage_color()

nc_color item::damage_color ( ) const

Provide color for UI display dependent upon current item damage level.

Definition at line 6289 of file item.cpp.

6290{
6291 // TODO: unify with veh_interact::countDurability
6292 switch( damage_level( 4 ) ) {
6293 default:
6294 // reinforced
6295 if( damage() <= min_damage() ) {
6296 // fully reinforced
6297 return c_green;
6298 } else {
6299 return c_light_green;
6300 }
6301 case 0:
6302 return c_light_green;
6303 case 1:
6304 return c_yellow;
6305 case 2:
6306 return c_magenta;
6307 case 3:
6308 return c_light_red;
6309 case 4:
6310 if( damage() >= max_damage() ) {
6311 return c_dark_gray;
6312 } else {
6313 return c_red;
6314 }
6315 }
6316}
int min_damage() const
Minimum amount of damage to an item (state of maximum repair)
Definition: item.cpp:6237

References c_dark_gray, c_green, c_light_green, c_light_red, c_magenta, c_red, c_yellow, damage(), damage_level(), max_damage(), and min_damage().

Referenced by durability_indicator(), vehicle_part::name(), and veh_utils::repair_part().

◆ damage_level()

int item::damage_level ( int  max) const

Scale item damage to the given number of levels.

This function is here mostly for back-compatibility. It should not be used when doing continuous math with the damage value: use damage() instead.

For example, for max = 4, min_damage = -1000, max_damage = 4000 damage level -1000 ~ -1 -1 0 0 1 ~ 1333 1 1334 ~ 2666 2 2667 ~ 3999 3 4000 4

Parameters
maxMaximum number of levels

Definition at line 705 of file item.cpp.

706{
707 if( damage_ == 0 || max <= 0 ) {
708 return 0;
709 } else if( max_damage() <= 1 ) {
710 return damage_ > 0 ? max : damage_;
711 } else if( damage_ < 0 ) {
712 return -( ( max - 1 ) * ( -damage_ - 1 ) / ( max_damage() - 1 ) + 1 );
713 } else {
714 return ( max - 1 ) * ( damage_ - 1 ) / ( max_damage() - 1 ) + 1;
715 }
716}

References damage_, and max_damage().

Referenced by Character::armor_absorb(), bash_resist(), bullet_resist(), activity_handlers::butcher_finish(), butchery_drops_harvest(), iuse::chainsaw_off(), crafting::complete_disassemble(), iuse::cs_lajatang_off(), cut_resist(), salvage_actor::cut_up(), damage_color(), vehicle_part::damage_level(), damage_melee(), damage_symbol(), veh_interact::do_repair(), durability_indicator(), gun_damage(), gun_dispersion(), avatar_funcs::gunmod_installation_odds(), monster::init_from_item(), vehicle_part::properties_to_item(), ready_to_revive(), repair_item_actor::repair_chance(), game::save_cyborg(), iuse::trimmer_off(), and fireweapon_off_actor::use().

◆ damage_melee()

int item::damage_melee ( damage_type  dt) const

Damage of given type caused when this item is used as melee weapon.

Definition at line 5214 of file item.cpp.

5215{
5216 assert( dt >= DT_NULL && dt < NUM_DT );
5217 if( is_null() ) {
5218 return 0;
5219 }
5220
5221 // effectiveness is reduced by 10% per damage level
5222 int res = type->melee[ dt ];
5223 res -= res * std::max( damage_level( 4 ), 0 ) * 0.1;
5224
5225 // apply type specific flags
5226 switch( dt ) {
5227 case DT_BASH:
5229 res *= 0.5;
5230 }
5231 break;
5232
5233 case DT_CUT:
5234 case DT_STAB:
5235 if( has_flag( flag_DIAMOND ) ) {
5236 res *= 1.3;
5237 }
5238 break;
5239
5240 default:
5241 break;
5242 }
5243
5244 // consider any melee gunmods
5245 if( is_gun() ) {
5246 const std::vector<const item *> &mods = gunmods();
5247 return std::accumulate( mods.begin(), mods.end(), res, [dt]( int last_max, const item * it ) {
5248 return it->has_flag( flag_MELEE_GUNMOD ) ? std::max( last_max, it->damage_melee( dt ) ) : last_max;
5249 } );
5250
5251 }
5252
5253 switch( dt ) {
5254 case DT_BASH:
5256 break;
5257 case DT_CUT:
5259 break;
5260 case DT_STAB:
5262 break;
5263 default:
5264 break;
5265 }
5266
5267 return std::max( res, 0 );
5268}
static const std::string flag_DIAMOND("DIAMOND")
static const std::string flag_REDUCED_BASHING("REDUCED_BASHING")
std::array< int, NUM_DT > melee
Damage output in melee for zero or more damage types.
Definition: itype.h:965

References bonus_from_enchantments_wielded(), damage_level(), DT_BASH, DT_CUT, DT_NULL, DT_STAB, flag_DIAMOND(), flag_REDUCED_BASHING(), gunmods(), has_flag(), is_gun(), is_null(), enchant_vals::ITEM_DAMAGE_BASH, enchant_vals::ITEM_DAMAGE_CUT, enchant_vals::ITEM_DAMAGE_STAB, itype::melee, NUM_DT, and type.

Referenced by base_damage_melee(), combat_info(), weapon_inventory_preset::deals_melee_damage(), character_effects::intimidation(), is_melee(), ma_requirements::is_valid_weapon(), melee_skill(), Character::melee_special_effects(), melee_train(), Character::power_rating(), activity_handlers::pulp_do_turn(), Character::reach_attack(), Character::roll_bash_damage(), Character::roll_cut_damage(), Character::roll_stab_damage(), smash(), and npc::smash_ability().

◆ damage_resist()

int item::damage_resist ( damage_type  dt,
bool  to_self = false 
) const

Resistance provided by this item against damage type given by an enum.

Definition at line 6397 of file item.cpp.

6398{
6399 switch( dt ) {
6400 case DT_NULL:
6401 case NUM_DT:
6402 return 0;
6403 case DT_TRUE:
6404 case DT_BIOLOGICAL:
6405 case DT_ELECTRIC:
6406 case DT_COLD:
6407 // Currently hardcoded:
6408 // Items can never be damaged by those types
6409 // But they provide 0 protection from them
6410 return to_self ? INT_MAX : 0;
6411 case DT_BASH:
6412 return bash_resist( to_self );
6413 case DT_CUT:
6414 return cut_resist( to_self );
6415 case DT_ACID:
6416 return acid_resist( to_self );
6417 case DT_STAB:
6418 return stab_resist( to_self );
6419 case DT_HEAT:
6420 return fire_resist( to_self );
6421 case DT_BULLET:
6422 return bullet_resist( to_self );
6423 default:
6424 debugmsg( "Invalid damage type: %d", dt );
6425 }
6426
6427 return 0;
6428}
int stab_resist(bool to_self=false) const
Definition: item.cpp:6118
@ DT_COLD
Definition: damage.h:29
@ DT_ELECTRIC
Definition: damage.h:30
@ DT_TRUE
Definition: damage.h:22
@ DT_ACID
Definition: damage.h:26
@ DT_BULLET
Definition: damage.h:31
@ DT_BIOLOGICAL
Definition: damage.h:23
@ DT_HEAT
Definition: damage.h:28

References acid_resist(), bash_resist(), bullet_resist(), cut_resist(), debugmsg, DT_ACID, DT_BASH, DT_BIOLOGICAL, DT_BULLET, DT_COLD, DT_CUT, DT_ELECTRIC, DT_HEAT, DT_NULL, DT_STAB, DT_TRUE, fire_resist(), NUM_DT, and stab_resist().

Referenced by Character::armor_absorb(), and resistances::resistances().

◆ damage_symbol()

std::string item::damage_symbol ( ) const

Provide prefix symbol for UI display dependent upon current item damage level.

Definition at line 6318 of file item.cpp.

6319{
6320 switch( damage_level( 4 ) ) {
6321 default:
6322 // reinforced
6323 return _( R"(++)" );
6324 case 0:
6325 return _( R"(||)" );
6326 case 1:
6327 return _( R"(|\)" );
6328 case 2:
6329 return _( R"(|.)" );
6330 case 3:
6331 return _( R"(\.)" );
6332 case 4:
6333 if( damage() >= max_damage() ) {
6334 return _( R"(XX)" );
6335 } else {
6336 return _( R"(..)" );
6337 }
6338
6339 }
6340}

References _, damage(), damage_level(), and max_damage().

Referenced by durability_indicator(), vehicle_part::name(), and veh_utils::repair_part().

◆ deactivate()

item & item::deactivate ( const Character ch = nullptr,
bool  alert = true 
)

Filter converting this instance to the inactive type If the item is either inactive or cannot be deactivated is a no-op.

Parameters
chcharacter currently possessing or acting upon the item (if any)
alertwhether to display any messages
Returns
same instance to allow method chaining

Definition at line 544 of file item.cpp.

545{
546 if( !active ) {
547 return *this; // no-op
548 }
549
550 if( is_tool() && type->tool->revert_to ) {
551 if( ch && alert && !type->tool->revert_msg.empty() ) {
552 ch->add_msg_if_player( m_info, _( type->tool->revert_msg ), tname() );
553 }
554 convert( *type->tool->revert_to );
555 active = false;
556
557 }
558 return *this;
559}
virtual void add_msg_if_player(const std::string &) const
Definition: creature.h:605
item & convert(const itype_id &new_type)
Filter converting this instance to another type preserving all other aspects.
Definition: item.cpp:537
@ m_info
Definition: enums.h:265

References _, active, Creature::add_msg_if_player(), alert, convert(), is_tool(), m_info, tname(), itype::tool, and type.

Referenced by iuse::note_bionics(), process_tool(), and fireweapon_on_actor::use().

◆ deserialize()

void item::deserialize ( JsonIn jsin)

Definition at line 2368 of file savegame_json.cpp.

2369{
2370 const JsonObject data = jsin.get_object();
2371 data.allow_omitted_members();
2372 io::JsonObjectInputArchive archive( data );
2373 io( archive );
2374 // made for fast forwarding time from 0.D to 0.E
2375 if( savegame_loading_version < 27 ) {
2377 }
2378 if( data.has_array( "contents" ) ) {
2379 std::list<item> items;
2380 data.read( "contents", items );
2381 contents = item_contents( items );
2382 } else {
2383 data.read( "contents", contents );
2384 }
2385
2386 // Sealed item migration: items with "unseals_into" set should always have contents
2388 convert( type->container->unseals_into );
2389 }
2390}
JsonObject get_object()
Definition: json.cpp:1432
bool has_array(const std::string &name) const
Definition: json.cpp:483
void allow_omitted_members() const
Definition: json.cpp:151
bool read(const std::string &name, T &t, bool throw_on_error=true) const
Definition: json.h:941
Input archive reading data from a Json object.
Definition: cata_io.h:185
void io(Archive &)
bool is_non_resealable_container() const
Whether removing this item's contents will permanently alter it.
Definition: item.cpp:6755
void legacy_fast_forward_time()
Definition: item.cpp:10045
int savegame_loading_version
Definition: savegame.cpp:64

References JsonObject::allow_omitted_members(), itype::container, contents, convert(), item_contents::empty(), JsonIn::get_object(), JsonObject::has_array(), io(), is_non_resealable_container(), legacy_fast_forward_time(), JsonObject::read(), savegame_loading_version, and type.

Referenced by item::craft_data::deserialize(), inventory::json_load_items(), monster::load(), and release_monster().

◆ destroyed_at_zero_charges()

bool item::destroyed_at_zero_charges ( ) const

Definition at line 6538 of file item.cpp.

6539{
6540 return ( is_ammo() || is_food() );
6541}

References is_ammo(), and is_food().

◆ detonate()

bool item::detonate ( const tripoint p,
std::vector< item > &  drops 
)

Detonates the item and adds remains (if any) to drops.

Returns true if the item actually detonated, potentially destroying other items and invalidating iterators. Should NOT be called on an item on the map, but on a local copy.

Definition at line 8771 of file item.cpp.

8772{
8773 if( type->explosion ) {
8775 return true;
8776 } else if( type->ammo && ( type->ammo->special_cookoff || type->ammo->cookoff ) ) {
8777 int charges_remaining = charges;
8778 const int rounds_exploded = rng( 1, charges_remaining );
8779 // Yank the exploding item off the map for the duration of the explosion
8780 // so it doesn't blow itself up.
8781 const islot_ammo &ammo_type = *type->ammo;
8782
8783 if( ammo_type.special_cookoff ) {
8784 // If it has a special effect just trigger it.
8785 apply_ammo_effects( p, ammo_type.ammo_effects, activated_by.get() );
8786 }
8787 charges_remaining -= rounds_exploded;
8788 if( charges_remaining > 0 ) {
8789 item temp_item = *this;
8790 temp_item.charges = charges_remaining;
8791 drops.push_back( temp_item );
8792 }
8793
8794 return true;
8795 } else if( !contents.empty() && ( !type->magazine || !type->magazine->protects_contents ) ) {
8796 std::vector<item *> removed_items;
8797 bool detonated = false;
8798 for( item *it : contents.all_items_top() ) {
8799 if( it->detonate( p, drops ) ) {
8800 removed_items.push_back( it );
8801 detonated = true;
8802 }
8803 }
8804 for( item *it : removed_items ) {
8805 remove_item( *it );
8806 }
8807 return detonated;
8808 }
8809
8810 return false;
8811}
safe_reference< Character > activated_by
Definition: item.h:2248
void explosion(const tripoint &p, Creature *source, float power, float factor, bool fire, int legacy_casing_mass, float)
Legacy explosion function.
Definition: explosion.cpp:1080
void apply_ammo_effects(const tripoint &p, const std::set< ammo_effect_str_id > &effects, Creature *source)
Definition: projectile.cpp:110
explosion_data explosion
Definition: itype.h:916

References activated_by, item_contents::all_items_top(), itype::ammo, ammo_type(), apply_ammo_effects(), charges, contents, item_contents::empty(), explosion_handler::explosion(), itype::explosion, itype::magazine, visitable< item >::remove_item(), rng(), and type.

Referenced by map::process_fields_in_submap(), and map::smash_items().

◆ disassembly_info()

void item::disassembly_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3195 of file item.cpp.

3197{
3199 return;
3200 }
3202 return;
3203 }
3204
3206 const requirement_data &req = dis.disassembly_requirements();
3207 if( !req.is_empty() ) {
3208 const std::string approx_time = to_string_approx( time_duration::from_turns( dis.time / 100 ) );
3209
3211 const std::string comps_str = enumerate_as_string( comps_list.begin(), comps_list.end(),
3212 []( const std::vector<item_comp> &comp_opts ) {
3213 return comp_opts.front().to_string();
3214 } );
3215
3216 std::vector<std::string> reqs_list;
3217 const requirement_data::alter_tool_comp_vector &tools_list = req.get_tools();
3218 for( const std::vector<tool_comp> &it : tools_list ) {
3219 if( !it.empty() ) {
3220 reqs_list.push_back( it.front().to_string() );
3221 }
3222 }
3224 for( const std::vector<quality_requirement> &it : quals_list ) {
3225 if( !it.empty() ) {
3226 reqs_list.push_back( it.front().to_colored_string() );
3227 }
3228 }
3229
3230 std::string descr;
3231 if( reqs_list.empty() ) {
3232 //~ 1 is approx. time (e.g. 'about 5 minutes'), 2 is a list of items
3233 descr = string_format( _( "<bold>Disassembly</bold> takes %1$s and might yield: %2$s." ),
3234 approx_time, comps_str );
3235 } else {
3236 const std::string reqs_str = enumerate_as_string( reqs_list );
3237 descr = string_format(
3238 //~ 1 is approx. time, 2 is a list of items and tools with qualities, 3 is a list of items.
3239 //~ Bold text in the middle makes it easier to see where the second list starts.
3240 _( "<bold>Disassembly</bold> takes %1$s, requires %2$s and <bold>might yield</bold>: %3$s." ),
3241 approx_time, reqs_str, comps_str );
3242 }
3243
3245 info.push_back( iteminfo( "DESCRIPTION", descr ) );
3246 }
3247}
std::string to_string_approx(const time_duration &dur, const bool verbose)
Returns approximate duration.
Definition: calendar.cpp:361
static const recipe & get_uncraft(const itype_id &id)
Returns disassembly recipe (or null recipe if no match)
Definition: recipe.h:35
requirement_data disassembly_requirements() const
If recipe can be used for disassembly fetch the combined requirements.
Definition: recipe.h:96
int time
Definition: recipe.h:61
static constexpr time_duration from_turns(const T t)
Named constructors to get a duration representing a multiple of the named time units.
Definition: calendar.h:204
@ DESCRIPTION_COMPONENTS_DISASSEMBLE
The *_vector members represent list of alternatives requirements: alter_tool_comp_vector = { * { { a,...
Definition: requirements.h:215
const alter_tool_comp_vector & get_tools() const
const alter_item_comp_vector & get_components() const
std::vector< std::vector< quality_requirement > > alter_quali_req_vector
Definition: requirements.h:222
bool is_empty() const
empty requirements are not necessary null
Definition: requirements.h:247
std::vector< std::vector< item_comp > > alter_item_comp_vector
Definition: requirements.h:223
const alter_quali_req_vector & get_qualities() const
std::vector< std::vector< tool_comp > > alter_tool_comp_vector
Definition: requirements.h:221

References _, components, DESCRIPTION_COMPONENTS_DISASSEMBLE, DESCRIPTION_COMPONENTS_MADEFROM, recipe::disassembly_requirements(), enumerate_as_string(), time_duration::from_turns(), requirement_data::get_components(), requirement_data::get_qualities(), requirement_data::get_tools(), recipe_dictionary::get_uncraft(), info(), insert_separation_line(), requirement_data::is_empty(), string_format(), iteminfo_query::test(), recipe::time, to_string_approx(), and typeId().

Referenced by info().

◆ display_money()

std::string item::display_money ( unsigned int  quantity,
unsigned int  total,
const std::optional< unsigned int > &  selected = std::nullopt 
) const

Definition at line 4825 of file item.cpp.

4827{
4828 if( selected ) {
4829 //~ This is a string to display the selected and total amount of money in a stack of cash cards.
4830 //~ %1$s is the display name of cash cards.
4831 //~ %2$s is the total amount of money.
4832 //~ %3$s is the selected amount of money.
4833 //~ Example: "cash cards $15.35 of $20.48"
4834 return string_format( pgettext( "cash card and money", "%1$s %3$s of %2$s" ), tname( quantity ),
4835 format_money( total ), format_money( *selected ) );
4836 } else {
4837 //~ This is a string to display the total amount of money in a stack of cash cards.
4838 //~ %1$s is the display name of cash cards.
4839 //~ %2$s is the total amount of money on the cash cards.
4840 //~ Example: "cash cards $20.48"
4841 return string_format( pgettext( "cash card and money", "%1$s %2$s" ), tname( quantity ),
4842 format_money( total ) );
4843 }
4844}
std::string format_money(int cents)
Definition: output.h:932
const char * pgettext(const char *context, const char *msgid)

References format_money(), pgettext(), string_format(), and tname().

Referenced by inventory_selector_preset::get_caption(), and selection_column_preset::get_caption().

◆ display_name()

std::string item::display_name ( unsigned int  quantity = 1) const

Returns the item name and the charges or contained charges (if the item can have charges at all).

Calls tname with given quantity and with_prefix being true.

Definition at line 4846 of file item.cpp.

4847{
4848 std::string name = tname( quantity );
4849 std::string sidetxt;
4850 std::string amt;
4851
4852 switch( get_side() ) {
4853 case side::BOTH:
4854 case side::num_sides:
4855 break;
4856 case side::LEFT:
4857 sidetxt = string_format( " (%s)", _( "left" ) );
4858 break;
4859 case side::RIGHT:
4860 sidetxt = string_format( " (%s)", _( "right" ) );
4861 break;
4862 }
4863 avatar &you = get_avatar();
4864 int amount = 0;
4865 int max_amount = 0;
4866 bool has_item = is_container() && contents.num_item_stacks() == 1;
4867 bool has_ammo = is_ammo_container() && contents.num_item_stacks() == 1;
4868 bool contains = has_item || has_ammo;
4869 bool show_amt = false;
4870 // We should handle infinite charges properly in all cases.
4871 if( contains ) {
4872 amount = contents.front().charges;
4874 } else if( is_book() && get_chapters() > 0 ) {
4875 // a book which has remaining unread chapters
4876 amount = get_remaining_chapters( you );
4877 } else if( ammo_capacity() > 0 ) {
4878 // anything that can be reloaded including tools, magazines, guns and auxiliary gunmods
4879 // but excluding bows etc., which have ammo, but can't be reloaded
4880 amount = ammo_remaining();
4881 max_amount = ammo_capacity();
4882 show_amt = !has_flag( flag_RELOAD_AND_SHOOT );
4883 } else if( count_by_charges() && !has_infinite_charges() ) {
4884 // A chargeable item
4885 amount = charges;
4886 max_amount = ammo_capacity();
4887 } else if( is_battery() ) {
4888 show_amt = true;
4889 amount = to_joule( energy_remaining() );
4890 max_amount = to_joule( type->battery->max_capacity );
4891 }
4892
4893 std::string ammotext;
4894 if( ( ( is_gun() && ammo_required() ) || is_magazine() ) && get_option<bool>( "AMMO_IN_NAMES" ) ) {
4895 if( !ammo_current().is_null() ) {
4896 ammotext = ammo_current()->nname( 1 );
4897 } else {
4898 ammotext = ammotype( *ammo_types().begin() )->name();
4899 }
4900 }
4901
4902 if( amount || show_amt ) {
4903 if( is_money() ) {
4904 amt = string_format( " $%.2f", amount / 100.0 );
4905 } else {
4906 if( !ammotext.empty() ) {
4907 ammotext = " " + ammotext;
4908 }
4909
4910 if( max_amount != 0 ) {
4911 amt = string_format( " (%i/%i%s)", amount, max_amount, ammotext );
4912 } else {
4913 amt = string_format( " (%i%s)", amount, ammotext );
4914 }
4915 }
4916 } else if( !ammotext.empty() ) {
4917 amt = " (" + ammotext + ")";
4918 }
4919
4920 // HACK: This is a hack to prevent possible crashing when displaying maps as items during character creation
4922 // TODO: fix point types
4923 tripoint map_pos_omt =
4924 get_var( "reveal_map_center_omt", you.global_omt_location().raw() );
4925 tripoint_abs_sm map_pos =
4926 project_to<coords::sm>( tripoint_abs_omt( map_pos_omt ) );
4927 const city *c = overmap_buffer.closest_city( map_pos ).city;
4928 if( c != nullptr ) {
4929 name = string_format( "%s %s", c->name, name );
4930 }
4931 }
4932
4933 return string_format( "%s%s%s", name, sidetxt, amt );
4934}
@ num_sides
tripoint_abs_omt global_omt_location() const
Returns the location of the player in global overmap terrain coordinates.
Definition: character.cpp:6269
constexpr Point & raw()
Definition: coordinates.h:111
bool is_ammo_container() const
Definition: item.cpp:6688
bool has_infinite_charges() const
Definition: item.cpp:9991
itype_id ammo_current() const
Specific ammo type, returns "null" if item is neither ammo nor loaded with any.
Definition: item.cpp:7577
bool is_map() const
Definition: item.cpp:6740
units::energy energy_remaining() const
Quantity of energy currently loaded in tool or battery.
Definition: item.cpp:7391
int charges_per_volume(const units::volume &vol) const
Number of (charges of) this item that fit into the given volume.
Definition: item.cpp:868
units::volume get_container_capacity() const
It returns the total capacity (volume) of the container for liquids.
Definition: item.cpp:8418
side get_side() const
Returns side item currently worn on.
Definition: item.cpp:812
int get_chapters() const
How many chapters the book has (if any).
Definition: item.cpp:7115
city_reference closest_city(const tripoint_abs_sm &center)
Find the closest city.
bool has_item(const item &it) const
Returns true if this visitable instance contains the item.
Definition: visitable.cpp:96
coords::coord_point< tripoint, coords::origin::abs, coords::omt > tripoint_abs_omt
Definition: coordinates.h:493
static const std::string flag_RELOAD_AND_SHOOT("RELOAD_AND_SHOOT")
const time_point turn_zero
Represents time point 0.
Definition: calendar.cpp:26
overmapbuffer overmap_buffer
const struct city * city
The city itself, points into overmap::cities.
Definition: overmapbuffer.h:81
Definition: overmap.h:55

References _, ammo_capacity(), ammo_current(), ammo_remaining(), ammo_required(), ammo_types(), itype::battery, BOTH, c, charges, charges_per_volume(), city_reference::city, overmapbuffer::closest_city(), contains, contents, count_by_charges(), energy_remaining(), flag_RELOAD_AND_SHOOT(), item_contents::front(), get_avatar(), get_chapters(), get_container_capacity(), get_remaining_chapters(), get_side(), get_var(), Character::global_omt_location(), has_flag(), has_infinite_charges(), visitable< item >::has_item(), is_ammo_container(), is_battery(), is_book(), is_container(), is_gun(), is_magazine(), is_map(), is_money(), is_null(), LEFT, ammunition_type::name(), om_direction::name(), itype::nname(), item_contents::num_item_stacks(), num_sides, overmap_buffer, coords::coord_point< Point, Origin, Scale >::raw(), RIGHT, string_format(), tname(), units::to_joule(), calendar::turn, calendar::turn_zero, and type.

Referenced by act_vehicle_unload_fuel(), monexamine::add_armor(), monexamine::attach_bag_to(), veh_interact::can_remove_part(), game_menus::inv::container_for(), inventory_selector_preset::get_caption(), selection_column_preset::get_caption(), liquid_handler::get_liquid_target(), game::handle_action(), handle_problematic_pickup(), pickup::handle_spillable_contents(), inscribe_actor::item_inscription(), game::list_items(), pick_one_up(), pickup::pick_up(), trading_window::update_win(), and musical_instrument_actor::use().

◆ display_stacked_with()

bool item::display_stacked_with ( const item rhs,
bool  check_components = false 
) const

Whether two items should stack when displayed in a inventory menu.

This is different from stacks_with, when two previously non-stackable items are now stackable and mergeable because, for example, they reaches the same temperature. This is necessary to avoid misleading stacks like "3 items-count-by-charge (5)".

Definition at line 888 of file item.cpp.

889{
890 return !count_by_charges() && stacks_with( rhs, check_components );
891}
bool stacks_with(const item &rhs, bool check_components=false, bool skip_type_check=false) const
Definition: item.cpp:893

References count_by_charges(), and stacks_with().

Referenced by pickup::stack_for_pickup_ui().

◆ dps() [1/2]

std::map< std::string, double > item::dps ( bool  for_display,
bool  for_calc 
) const

Definition at line 1447 of file item.cpp.

1448{
1449 return dps( for_display, for_calc, get_avatar() );
1450}

References dps(), and get_avatar().

◆ dps() [2/2]

std::map< std::string, double > item::dps ( bool  for_display,
bool  for_calc,
const player guy 
) const

calculate effective dps against a stock set of monsters.

by default, assume g->u is wielding for_display - include monsters intended for display purposes for_calc - include monsters intended for evaluation purposes for_display and for_calc are inclusive

Definition at line 1432 of file item.cpp.

1434{
1435 std::map<std::string, double> results;
1436 for( const std::pair<translation, dps_comp_data> &comp_mon : dps_comp_monsters ) {
1437 if( ( comp_mon.second.display != for_display ) &&
1438 ( comp_mon.second.evaluate != for_calc ) ) {
1439 continue;
1440 }
1441 monster test_mon = monster( comp_mon.second.mon_id );
1442 results[ comp_mon.first.translated() ] = effective_dps( guy, test_mon );
1443 }
1444 return results;
1445}
double effective_dps(const player &guy, const monster &mon) const
Calculate the item's effective damage per second past armor when wielded by a character against a mon...
Definition: item.cpp:1329
static const std::vector< std::pair< translation, dps_comp_data > > dps_comp_monsters
Definition: item.cpp:1425

References dps_comp_monsters, and effective_dps().

Referenced by average_dps(), combat_info(), dps(), and ideal_ranged_dps().

◆ durability_indicator()

std::string item::durability_indicator ( bool  include_intact = false) const

Provides a prefix for the durability state of the item.

with ITEM_HEALTH_BAR enabled, returns a symbol with color tag already applied. Otherwise, returns an adjective. if include_intact is true, this provides a string for the corner case of a player with ITEM_HEALTH_BAR disabled, but we need still a string for some reason.

Definition at line 6342 of file item.cpp.

6343{
6344 std::string outputstring;
6345
6346 if( damage() < 0 ) {
6347 if( get_option<bool>( "ITEM_HEALTH_BAR" ) ) {
6348 outputstring = colorize( damage_symbol() + "\u00A0", damage_color() );
6349 } else if( is_gun() ) {
6350 outputstring = pgettext( "damage adjective", "accurized " );
6351 } else {
6352 outputstring = pgettext( "damage adjective", "reinforced " );
6353 }
6354 } else if( has_flag( flag_CORPSE ) ) {
6355 if( damage() > 0 ) {
6356 switch( damage_level( 4 ) ) {
6357 case 1:
6358 outputstring = pgettext( "damage adjective", "bruised " );
6359 break;
6360 case 2:
6361 outputstring = pgettext( "damage adjective", "damaged " );
6362 break;
6363 case 3:
6364 outputstring = pgettext( "damage adjective", "mangled " );
6365 break;
6366 default:
6367 outputstring = pgettext( "damage adjective", "pulped " );
6368 break;
6369 }
6370 }
6371 } else if( get_option<bool>( "ITEM_HEALTH_BAR" ) ) {
6372 outputstring = colorize( damage_symbol() + "\u00A0", damage_color() );
6373 } else {
6374 outputstring = string_format( "%s ", get_base_material().dmg_adj( damage_level( 4 ) ) );
6375 if( include_intact && outputstring == " " ) {
6376 outputstring = _( "fully intact " );
6377 }
6378 }
6379
6380 return outputstring;
6381}
std::string damage_symbol() const
Provide prefix symbol for UI display dependent upon current item damage level.
Definition: item.cpp:6318
const material_type & get_base_material() const
Get the basic (main) material of this item.
Definition: item.cpp:7177
nc_color damage_color() const
Provide color for UI display dependent upon current item damage level.
Definition: item.cpp:6289

References _, colorize(), damage(), damage_color(), damage_level(), damage_symbol(), flag_CORPSE(), get_base_material(), has_flag(), is_gun(), pgettext(), and string_format().

Referenced by colorized_item_name(), damage_item(), iuse::gun_repair(), repair_item_actor::repair(), and tname().

◆ effective_dps()

double item::effective_dps ( const player guy,
const monster mon 
) const

Calculate the item's effective damage per second past armor when wielded by a character against a monster.

Definition at line 1329 of file item.cpp.

1330{
1331 const float mon_dodge = mon.get_dodge();
1332 float base_hit = guy.get_dex() / 4.0f + guy.get_hit_weapon( *this );
1333 base_hit *= std::max( 0.25f, 1.0f - guy.encumb( bp_torso ) / 100.0f );
1334 float mon_defense = mon_dodge + mon.size_melee_penalty() / 5.0;
1335 constexpr double hit_trials = 10000.0;
1336 const int rng_mean = std::max( std::min( static_cast<int>( base_hit - mon_defense ), 20 ),
1337 -20 ) + 20;
1338 double num_all_hits = hits_by_accuracy[ rng_mean ];
1339 /* critical hits have two chances to occur: triple critical hits happen much less frequently,
1340 * and double critical hits can only occur if a hit roll is more than 1.5 * monster dodge.
1341 * Not the hit roll used to determine the attack, another one.
1342 * the way the math works, some percentage of the total hits are eligible to be double
1343 * critical hits, and the rest are eligible to be triple critical hits, but in each case,
1344 * only some small percent of them actually become critical hits.
1345 */
1346 const int rng_high_mean = std::max( std::min( static_cast<int>( base_hit - 1.5 * mon_dodge ),
1347 20 ), -20 ) + 20;
1348 double num_high_hits = hits_by_accuracy[ rng_high_mean ] * num_all_hits / hit_trials;
1349 double double_crit_chance = guy.crit_chance( 4, 0, *this );
1350 double crit_chance = guy.crit_chance( 0, 0, *this );
1351 double num_low_hits = std::max( 0.0, num_all_hits - num_high_hits );
1352
1353 double moves_per_attack = guy.attack_cost( *this );
1354 // attacks that miss do no damage but take time
1355 double total_moves = ( hit_trials - num_all_hits ) * moves_per_attack;
1356 double total_damage = 0.0;
1357 double num_crits = std::min( num_low_hits * crit_chance + num_high_hits * double_crit_chance,
1358 num_all_hits );
1359 // critical hits are counted separately
1360 double num_hits = num_all_hits - num_crits;
1361 // sum average damage past armor and return the number of moves required to achieve
1362 // that damage
1363 const auto calc_effective_damage = [ &, moves_per_attack]( const double num_strikes,
1364 const bool crit, const player & guy, const monster & mon ) {
1365 monster temp_mon = mon;
1366 double subtotal_damage = 0;
1367 damage_instance base_damage;
1368 guy.roll_all_damage( crit, base_damage, true, *this );
1369 damage_instance dealt_damage = base_damage;
1370 temp_mon.absorb_hit( bodypart_id( "torso" ), dealt_damage );
1371 dealt_damage_instance dealt_dams;
1372 for( const damage_unit &dmg_unit : dealt_damage.damage_units ) {
1373 int cur_damage = 0;
1374 int total_pain = 0;
1375 temp_mon.deal_damage_handle_type( dmg_unit, bodypart_id( "torso" ), cur_damage, total_pain );
1376 if( cur_damage > 0 ) {
1377 dealt_dams.dealt_dams[ dmg_unit.type ] += cur_damage;
1378 }
1379 }
1380 double damage_per_hit = dealt_dams.total_damage();
1381 subtotal_damage = damage_per_hit * num_strikes;
1382 double subtotal_moves = moves_per_attack * num_strikes;
1383
1384 if( has_technique( rapid_strike ) ) {
1385 monster temp_rs_mon = mon;
1386 damage_instance rs_base_damage;
1387 guy.roll_all_damage( crit, rs_base_damage, true, *this );
1388 damage_instance dealt_rs_damage = rs_base_damage;
1389 for( damage_unit &dmg_unit : dealt_rs_damage.damage_units ) {
1390 dmg_unit.damage_multiplier *= 0.66;
1391 }
1392 temp_rs_mon.absorb_hit( bodypart_id( "torso" ), dealt_rs_damage );
1393 dealt_damage_instance rs_dealt_dams;
1394 for( const damage_unit &dmg_unit : dealt_rs_damage.damage_units ) {
1395 int cur_damage = 0;
1396 int total_pain = 0;
1397 temp_rs_mon.deal_damage_handle_type( dmg_unit, bodypart_id( "torso" ), cur_damage, total_pain );
1398 if( cur_damage > 0 ) {
1399 rs_dealt_dams.dealt_dams[ dmg_unit.type ] += cur_damage;
1400 }
1401 }
1402 double rs_damage_per_hit = rs_dealt_dams.total_damage();
1403 subtotal_moves *= 0.5;
1404 subtotal_damage *= 0.5;
1405 subtotal_moves += moves_per_attack * num_strikes * 0.33;
1406 subtotal_damage += rs_damage_per_hit * num_strikes * 0.5;
1407 }
1408 return std::make_pair( subtotal_moves, subtotal_damage );
1409 };
1410 std::pair<double, double> crit_summary = calc_effective_damage( num_crits, true, guy, mon );
1411 total_moves += crit_summary.first;
1412 total_damage += crit_summary.second;
1413 std::pair<double, double> summary = calc_effective_damage( num_hits, false, guy, mon );
1414 total_moves += summary.first;
1415 total_damage += summary.second;
1416 return total_damage * to_moves<double>( 1_seconds ) / total_moves;
1417}
int_id< body_part_type > bodypart_id
Definition: bodypart.h:25
virtual int get_dex() const
Definition: character.cpp:4093
float get_hit_weapon(const item &weap) const
Gets melee accuracy component from weapon+skills.
Definition: melee.cpp:335
int encumb(body_part bp) const
Returns ENC provided by armor, etc.
Definition: character.cpp:4026
int size_melee_penalty() const
Definition: creature.cpp:484
bool has_technique(const matec_id &tech) const
Whether the item supports a specific martial art technique (either through its type,...
Definition: item.cpp:5465
void deal_damage_handle_type(const damage_unit &du, bodypart_id bp, int &damage, int &pain) override
Definition: monster.cpp:1627
float get_dodge() const override
Definition: monster.cpp:2008
void absorb_hit(const bodypart_id &bp, damage_instance &dam) override
Definition: monster.cpp:1410
Definition: player.h:84
static const double hits_by_accuracy[41]
Definition: item.cpp:1317
static const matec_id rapid_strike("RAPID")
damage_type type
Definition: damage.h:36
float damage_multiplier
Definition: damage.h:40
std::array< int, NUM_DT > dealt_dams
Definition: damage.h:86
int total_damage() const
Definition: damage.cpp:180

References monster::absorb_hit(), Character::attack_cost(), bp_torso, Character::crit_chance(), damage_unit::damage_multiplier, damage_instance::damage_units, monster::deal_damage_handle_type(), dealt_damage_instance::dealt_dams, Character::encumb(), Character::get_dex(), monster::get_dodge(), Character::get_hit_weapon(), has_technique(), hits_by_accuracy, rapid_strike, Character::roll_all_damage(), Creature::size_melee_penalty(), dealt_damage_instance::total_damage(), and damage_unit::type.

Referenced by dps().

◆ energy_remaining()

units::energy item::energy_remaining ( ) const

Quantity of energy currently loaded in tool or battery.

Definition at line 7391 of file item.cpp.

7392{
7393 if( is_battery() ) {
7394 return energy;
7395 }
7396
7397 return 0_J;
7398}
units::energy energy
Definition: item.h:2210

References energy, and is_battery().

Referenced by display_name(), mod_energy(), process_vehicle_items(), and charger_tile::update_internal().

◆ engine_displacement()

int item::engine_displacement ( ) const

for combustion engines the displacement (cc)

Definition at line 4138 of file item.cpp.

4139{
4140 return type->engine ? type->engine->displacement : 0;
4141}
cata::value_ptr< islot_engine > engine
Definition: itype.h:827

References itype::engine, and type.

Referenced by veh_interact::display_details(), vehicle_part::name(), vehicle::part_vpower_w(), and tname().

◆ erase_var()

void item::erase_var ( const std::string &  name)

◆ faults_potential()

std::set< fault_id > item::faults_potential ( ) const

What faults can potentially occur with this item?

Definition at line 6830 of file item.cpp.

6831{
6832 std::set<fault_id> res;
6833 res.insert( type->faults.begin(), type->faults.end() );
6834 return res;
6835}
std::set< fault_id > faults
What faults (if any) can occur.
Definition: itype.h:988

References itype::faults, and type.

Referenced by vehicle_part::faults_potential(), ranged::handle_gun_damage(), and examine_item_menu::rate_action_mend().

◆ fill_with()

void item::fill_with ( item liquid,
int  amount = INFINITE_CHARGES 
)

Fill item with liquid up to its capacity.

This works for guns and tools that accept liquid ammo.

Parameters
liquidLiquid to fill the container with.
amountAmount to fill item with, capped by remaining capacity

Definition at line 8585 of file item.cpp.

8586{
8587 amount = std::min( get_remaining_capacity_for_liquid( liquid, true ),
8588 std::min( amount, liquid.charges ) );
8589 if( amount <= 0 ) {
8590 return;
8591 }
8592
8593 if( !is_container() ) {
8594 if( !is_reloadable_with( liquid.typeId() ) ) {
8595 debugmsg( "Tried to fill %s which is not a container and can't be reloaded with %s.",
8596 tname(), liquid.tname() );
8597 return;
8598 }
8599 ammo_set( liquid.typeId(), ammo_remaining() + amount );
8600 } else if( is_food_container() ) {
8601 item &cts = contents.front();
8602 // Use maximum rot between the two
8603 cts.set_relative_rot( std::max( cts.get_relative_rot(),
8604 liquid.get_relative_rot() ) );
8605 cts.mod_charges( amount );
8606 } else if( !is_container_empty() ) {
8607 // if container already has liquid we need to set the amount
8608 item &cts = contents.front();
8609 cts.mod_charges( amount );
8610 } else {
8611 item liquid_copy( liquid );
8612 liquid_copy.charges = amount;
8613 put_in( liquid_copy );
8614 }
8615
8616 liquid.mod_charges( -amount );
8618}
bool is_reloadable_with(const itype_id &ammo) const
Returns true if this item can be reloaded with specified ammo type at this moment.
Definition: item.cpp:6897
void mod_charges(int mod)
Modify the charges of this item, only use for items counted by charges! The item must have enough cha...
Definition: item.cpp:9751
void on_contents_changed()
Callback when contents of the item are affected in any way other than just processing.
Definition: item.cpp:4559
int get_remaining_capacity_for_liquid(const item &liquid, bool allow_bucket=false, std::string *err=nullptr) const
How much more of this liquid (in charges) can be put in this container.
Definition: item.cpp:8447

References ammo_remaining(), ammo_set(), charges, contents, debugmsg, item_contents::front(), get_relative_rot(), get_remaining_capacity_for_liquid(), is_container(), is_container_empty(), is_food_container(), is_reloadable_with(), mod_charges(), on_contents_changed(), put_in(), set_relative_rot(), tname(), and typeId().

Referenced by veh_interact::complete_vehicle(), vehicle_part::fill_with(), advanced_inventory::move_content(), Character::pour_into(), and reload().

◆ final_info()

void item::final_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3647 of file item.cpp.

3649{
3650 if( is_null() ) {
3651 return;
3652 }
3653
3654 // TODO: Remove
3655 const iteminfo_query *parts = &parts_ref;
3656
3657 const std::string space = " ";
3658
3660
3661 if( parts->test( iteminfo_parts::BASE_RIGIDITY ) ) {
3662 if( !type->rigid ) {
3663 info.emplace_back( "BASE",
3664 _( "* This item is <info>not rigid</info>. Its"
3665 " volume and encumbrance increase with contents." ) );
3666 }
3667 }
3668
3670 if( !conductive() ) {
3671 info.push_back( iteminfo( "BASE", _( "* This item <good>does not "
3672 "conduct</good> electricity." ) ) );
3673 } else if( has_flag( flag_CONDUCTIVE ) ) {
3674 info.push_back( iteminfo( "BASE",
3675 _( "* This item effectively <bad>conducts</bad> "
3676 "electricity, as it has no guard." ) ) );
3677 } else {
3678 info.push_back( iteminfo( "BASE", _( "* This item <bad>conducts</bad> electricity." ) ) );
3679 }
3680 }
3681
3682 avatar &you = get_avatar();
3683 if( is_armor() && you.has_trait( trait_WOOLALLERGY ) &&
3684 ( made_of( material_id( "wool" ) ) || has_own_flag( "wooled" ) ) ) {
3685 info.push_back( iteminfo( "DESCRIPTION",
3686 _( "* This clothing will give you an <bad>allergic "
3687 "reaction</bad>." ) ) );
3688 }
3689
3690 if( parts->test( iteminfo_parts::DESCRIPTION_FLAGS ) ) {
3691 // concatenate base and acquired flags...
3692 std::vector<std::string> flags;
3693 std::set_union( type->get_flags().begin(), type->get_flags().end(),
3694 get_flags().begin(), get_flags().end(),
3695 std::back_inserter( flags ) );
3696
3697 // ...and display those which have an info description
3698 for( const std::string &e : flags ) {
3699 const json_flag &f = json_flag::get( e );
3700 if( !f.info().empty() ) {
3701 info.emplace_back( "DESCRIPTION", string_format( "* %s", _( f.info() ) ) );
3702 }
3703 }
3704 }
3705
3706 armor_fit_info( info, parts, batch, debug );
3707
3708 if( is_tool() ) {
3710 info.push_back( iteminfo( "DESCRIPTION",
3711 _( "* This tool can draw power from a <info>Bionic Armor Interface</info>" ) ) );
3712 }
3714 info.push_back( iteminfo( "DESCRIPTION",
3715 _( "* This tool uses a <info>universal power supply</info> "
3716 "and is <neutral>not compatible</neutral> with "
3717 "<info>standard batteries</info>." ) ) );
3718 } else if( has_flag( flag_RECHARGE ) && has_flag( flag_NO_RELOAD ) &&
3720 info.push_back( iteminfo( "DESCRIPTION",
3721 _( "* This tool has a <info>rechargeable power cell</info> "
3722 "and is <neutral>not compatible</neutral> with "
3723 "<info>standard batteries</info>." ) ) );
3724 } else if( has_flag( flag_RECHARGE ) &&
3726 info.push_back( iteminfo( "DESCRIPTION",
3727 _( "* This tool has a <info>rechargeable power cell</info> "
3728 "and can be recharged in any <neutral>UPS-compatible "
3729 "recharging station</neutral>. You could charge it with "
3730 "<info>standard batteries</info>, but unloading it is "
3731 "impossible." ) ) );
3732 } else if( has_flag( flag_USES_BIONIC_POWER ) ) {
3733 info.emplace_back( "DESCRIPTION",
3734 _( "* This tool <info>runs on bionic power</info>." ) );
3735 }
3736 }
3737
3740 if( has_flag( flag_RADIO_MOD ) ) {
3741 info.emplace_back( "DESCRIPTION",
3742 _( "* This item has been modified to listen to <info>radio "
3743 "signals</info>. It can still be activated manually." ) );
3744 } else {
3745 info.emplace_back( "DESCRIPTION",
3746 _( "* This item can only be activated by a <info>radio "
3747 "signal</info>." ) );
3748 }
3749
3750 std::string signame;
3751 if( has_flag( flag_RADIOSIGNAL_1 ) ) {
3752 signame = "<color_c_red>red</color> radio signal.";
3753 } else if( has_flag( flag_RADIOSIGNAL_2 ) ) {
3754 signame = "<color_c_blue>blue</color> radio signal.";
3755 } else if( has_flag( flag_RADIOSIGNAL_3 ) ) {
3756 signame = "<color_c_green>green</color> radio signal.";
3757 }
3759 info.emplace_back( "DESCRIPTION",
3760 string_format( _( "* It will be activated by the %s." ),
3761 signame ) );
3762 }
3763
3766 info.emplace_back( "DESCRIPTION",
3767 _( "* Activating this item with a <info>radio signal</info> will "
3768 "<neutral>detonate</neutral> it immediately." ) );
3769 }
3770 }
3771
3772 bionic_info( info, parts, batch, debug );
3773
3774 if( is_gun() && has_flag( flag_FIRE_TWOHAND ) &&
3776 info.push_back( iteminfo( "DESCRIPTION",
3777 _( "* This weapon needs <info>two free hands</info> "
3778 "to fire." ) ) );
3779 }
3780
3783 info.push_back( iteminfo( "DESCRIPTION",
3784 _( "* This mod <bad>obscures sights</bad> of the "
3785 "base weapon." ) ) );
3786 }
3787
3788 if( is_gunmod() && has_flag( flag_CONSUMABLE ) &&
3790 info.push_back( iteminfo( "DESCRIPTION",
3791 _( "* This mod might <bad>suffer wear</bad> when firing "
3792 "the base weapon." ) ) );
3793 }
3794
3797 info.push_back( iteminfo( "DESCRIPTION",
3798 _( "* The casing of this item has <neutral>cracked</neutral>, "
3799 "revealing an <info>ominous green glow</info>." ) ) );
3800 }
3801
3804 info.push_back( iteminfo( "DESCRIPTION",
3805 _( "* This object is <neutral>surrounded</neutral> by a "
3806 "<info>sickly green glow</info>." ) ) );
3807 }
3808
3809 if( is_brewable() || ( !contents.empty() && contents.front().is_brewable() ) ) {
3810 const item &brewed = !is_brewable() ? contents.front() : *this;
3812 const time_duration btime = brewed.brewing_time();
3813 int btime_i = to_days<int>( btime );
3814 if( btime <= 2_days ) {
3815 btime_i = to_hours<int>( btime );
3816 info.push_back( iteminfo( "DESCRIPTION",
3817 string_format( vgettext( "* Once set in a vat, this "
3818 "will ferment in around %d hour.",
3819 "* Once set in a vat, this will ferment in "
3820 "around %d hours.", btime_i ), btime_i ) ) );
3821 } else {
3822 info.push_back( iteminfo( "DESCRIPTION",
3823 string_format( vgettext( "* Once set in a vat, this "
3824 "will ferment in around %d day.",
3825 "* Once set in a vat, this will ferment in "
3826 "around %d days.", btime_i ), btime_i ) ) );
3827 }
3828 }
3830 for( const itype_id &res : brewed.brewing_results() ) {
3831 info.push_back( iteminfo( "DESCRIPTION",
3832 string_format( _( "* Fermenting this will produce "
3833 "<neutral>%s</neutral>." ),
3834 nname( res, brewed.charges ) ) ) );
3835 }
3836 }
3837 }
3838
3840 for( const fault_id &e : faults ) {
3841 //~ %1$s is the name of a fault and %2$s is the description of the fault
3842 info.emplace_back( "DESCRIPTION", string_format( _( "* <bad>%1$s</bad>. %2$s" ),
3843 e.obj().name(), e.obj().description() ) );
3844 }
3845 }
3846
3847 // does the item fit in any holsters?
3848 std::vector<const itype *> holsters = item_controller->find( [this]( const itype & e ) {
3849 if( !e.can_use( "holster" ) ) {
3850 return false;
3851 }
3852 const holster_actor *ptr = dynamic_cast<const holster_actor *>
3853 ( e.get_use( "holster" )->get_actor_ptr() );
3854 return ptr->can_holster( *this );
3855 } );
3856
3857 if( !holsters.empty() && parts->test( iteminfo_parts::DESCRIPTION_HOLSTERS ) ) {
3859 info.emplace_back( "DESCRIPTION", _( "<bold>Can be stored in</bold>: " ) +
3860 enumerate_as_string( holsters.begin(), holsters.end(),
3861 []( const itype * e ) {
3862 return e->nname( 1 );
3863 } ) );
3864 }
3865
3867 for( auto &u : type->use_methods ) {
3868 const delayed_transform_iuse *tt = dynamic_cast<const delayed_transform_iuse *>
3869 ( u.second.get_actor_ptr() );
3870 if( tt == nullptr ) {
3871 continue;
3872 }
3873 const int time_to_do = tt->time_to_do( *this );
3874 if( time_to_do <= 0 ) {
3875 info.push_back( iteminfo( "DESCRIPTION",
3876 _( "It's done and <info>can be activated</info>." ) ) );
3877 } else {
3878 const std::string time = to_string_clipped( time_duration::from_turns( time_to_do ) );
3879 info.push_back( iteminfo( "DESCRIPTION",
3880 string_format( _( "It will be done in %s." ),
3881 time.c_str() ) ) );
3882 }
3883 }
3884 }
3885
3886 std::map<std::string, std::string>::const_iterator item_note = item_vars.find( "item_note" );
3887 std::map<std::string, std::string>::const_iterator item_note_tool =
3888 item_vars.find( "item_note_tool" );
3889
3890 if( item_note != item_vars.end() && parts->test( iteminfo_parts::DESCRIPTION_NOTES ) ) {
3892 std::string ntext;
3893 const inscribe_actor *use_actor = nullptr;
3894 if( item_note_tool != item_vars.end() ) {
3895 const use_function *use_func = itype_id( item_note_tool->second )->get_use( "inscribe" );
3896 use_actor = dynamic_cast<const inscribe_actor *>( use_func->get_actor_ptr() );
3897 }
3898 if( use_actor ) {
3899 //~ %1$s: gerund (e.g. carved), %2$s: item name, %3$s: inscription text
3900 ntext = string_format( pgettext( "carving", "%1$s on the %2$s is: %3$s" ),
3901 use_actor->gerund, tname(), item_note->second );
3902 } else {
3903 //~ %1$s: inscription text
3904 ntext = string_format( pgettext( "carving", "Note: %1$s" ), item_note->second );
3905 }
3906 info.push_back( iteminfo( "DESCRIPTION", ntext ) );
3907 }
3908
3909 if( this->get_var( "die_num_sides", 0 ) != 0 ) {
3910 info.emplace_back( "DESCRIPTION",
3911 string_format( _( "* This item can be used as a <info>die</info>, "
3912 "and has <info>%d</info> sides." ),
3913 static_cast<int>( this->get_var( "die_num_sides",
3914 0 ) ) ) );
3915 }
3916
3917 // Price and barter value
3918 const int price_preapoc = price( false ) * batch;
3919 const int price_postapoc = price( true ) * batch;
3920 if( parts->test( iteminfo_parts::BASE_PRICE ) ) {
3922 info.push_back( iteminfo( "BASE", _( "Price: " ), _( "$<num>" ),
3924 static_cast<double>( price_preapoc ) / 100 ) );
3925 }
3926 if( price_preapoc != price_postapoc && parts->test( iteminfo_parts::BASE_BARTER ) ) {
3927 info.push_back( iteminfo( "BASE", space + _( "Barter value: " ), _( "$<num>" ),
3929 static_cast<double>( price_postapoc ) / 100 ) );
3930 }
3931
3932 // Recipes using this item as an ingredient
3934 itype_id tid = contents.empty() ? typeId() : contents.front().typeId();
3935 const inventory &crafting_inv = you.crafting_inventory();
3936
3937 const recipe_subset available_recipe_subset = you.get_available_recipes( crafting_inv, nullptr,
3939 const std::set<const recipe *> &item_recipes = available_recipe_subset.of_component( tid );
3940
3941 if( item_recipes.empty() ) {
3943 info.push_back( iteminfo( "DESCRIPTION",
3944 _( "You know of nothing you could craft with it." ) ) );
3945 } else {
3946 if( item_recipes.size() > 24 ) {
3948 info.push_back( iteminfo( "DESCRIPTION",
3949 _( "You know dozens of things you could craft with it." ) ) );
3950 } else if( item_recipes.size() > 12 ) {
3952 info.push_back( iteminfo( "DESCRIPTION",
3953 _( "You could use it to craft various other things." ) ) );
3954 } else {
3955 // Extract item names from recipes and sort them
3956 std::vector<std::pair<std::string, bool>> result_names;
3958 item_recipes.begin(), item_recipes.end(),
3959 std::back_inserter( result_names ),
3960 [&crafting_inv]( const recipe * r ) {
3961 bool can_make = r->deduped_requirements().can_make_with_inventory(
3962 crafting_inv, r->get_component_filter() );
3963 return std::make_pair( r->result_name(), can_make );
3964 } );
3965 std::sort( result_names.begin(), result_names.end(), localized_compare );
3966 const std::string recipes =
3967 enumerate_as_string( result_names.begin(), result_names.end(),
3968 []( const std::pair<std::string, bool> &p ) {
3969 if( p.second ) {
3970 return p.first;
3971 } else {
3972 return string_format( "<dark>%s</dark>", p.first );
3973 }
3974 } );
3976 info.push_back( iteminfo( "DESCRIPTION",
3977 string_format( _( "You could use it to craft: %s" ),
3978 recipes ) ) );
3979 }
3980 }
3981 }
3982 if( get_option<bool>( "ENABLE_ASCII_ART_ITEM" ) ) {
3983 const ascii_art_id art = type->picture_id;
3984 if( art.is_valid() ) {
3985 for( const std::string &line : art->picture ) {
3986 info.push_back( iteminfo( "DESCRIPTION", line ) );
3987 }
3988 }
3989 }
3990}
static std::string to_string_clipped(const int num, const clipped_unit type, const clipped_align align)
Definition: calendar.cpp:228
const inventory & crafting_inventory(bool clear_path)
Definition: crafting.cpp:557
std::vector< std::string > picture
Definition: ascii_art.h:22
iterator begin() const
Definition: flat_set.h:83
iterator end() const
Definition: flat_set.h:86
This is a iuse_transform that uses the age of the item instead of a counter.
Definition: iuse_actor.h:289
int time_to_do(const item &it) const
How much longer (in turns) until the transformation can be done, can be negative.
Definition: iuse_actor.cpp:883
Writes on stuff (ground or items)
Definition: iuse_actor.h:610
translation gerund
Definition: iuse_actor.h:633
const FlagsSetType & get_flags() const
returs read-only set of flags of this item (not including flags from item type or gunmods)
Definition: item.cpp:5379
const std::vector< itype_id > & brewing_results() const
The results of fermenting this item.
Definition: item.cpp:5977
std::set< fault_id > faults
What faults (if any) currently apply to this item.
Definition: item.h:2174
time_duration brewing_time() const
Time for this item to be fully fermented.
Definition: item.cpp:5972
bool conductive() const
Whether the items is conductive.
Definition: item.cpp:6504
void bionic_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3296
int price(bool practical) const
Returns the monetary value of an item.
Definition: item.cpp:4947
void armor_fit_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:2761
Definition: flag.h:15
std::string info() const
Get informative text for display in UI.
Definition: flag.h:30
recipe_subset get_available_recipes(const inventory &crafting_inv, const std::vector< npc * > *helpers=nullptr, recipe_filter filter=nullptr) const
Returns all available recipes (from books and npc companions)
Definition: player.cpp:298
const std::set< const recipe * > & of_component(const itype_id &id) const
Returns all recipes which could use component.
static const std::string flag_RADIOSIGNAL_2("RADIOSIGNAL_2")
static const std::string flag_FIRE_TWOHAND("FIRE_TWOHAND")
static const std::string flag_RADIOSIGNAL_1("RADIOSIGNAL_1")
static const std::string flag_DISABLE_SIGHTS("DISABLE_SIGHTS")
static const std::string flag_USE_UPS("USE_UPS")
static const std::string flag_RECHARGE("RECHARGE")
static const std::string flag_RADIO_ACTIVATION("RADIO_ACTIVATION")
static const std::string flag_RADIO_INVOKE_PROC("RADIO_INVOKE_PROC")
static const std::string flag_CONSUMABLE("CONSUMABLE")
static const std::string flag_NO_RELOAD("NO_RELOAD")
static const std::string flag_RADIOSIGNAL_3("RADIOSIGNAL_3")
static const std::string flag_LEAK_ALWAYS("LEAK_ALWAYS")
static const std::string flag_RADIO_MOD("RADIO_MOD")
std::unique_ptr< Item_factory > item_controller
@ DESCRIPTION_RECHARGE_UPSCAPABLE
@ DESCRIPTION_GUNMOD_DISABLESSIGHTS
@ DESCRIPTION_BREWABLE_DURATION
@ DESCRIPTION_RADIO_ACTIVATION_CHANNEL
@ DESCRIPTION_BREWABLE_PRODUCTS
@ DESCRIPTION_RECHARGE_NORELOAD
@ DESCRIPTION_ACTIVATABLE_TRANSFORMATION
@ DESCRIPTION_BIONIC_ARMOR_INTERFACE
@ DESCRIPTION_RADIOACTIVITY_DAMAGED
@ DESCRIPTION_RADIO_ACTIVATION_PROC
@ DESCRIPTION_RECHARGE_UPSMODDED
@ DESCRIPTION_GUNMOD_CONSUMABLE
@ DESCRIPTION_RADIOACTIVITY_ALWAYS
@ DESCRIPTION_RADIO_ACTIVATION
@ DESCRIPTION_APPLICABLE_RECIPES
void line(map *m, const ter_id &type, point p1, point p2)
Definition: mapgen.cpp:6290
void transform(player &p, const tripoint &pos)
Transform the examined object into the object specified by its transforms_into property.
Definition: iexamine.cpp:1557
recipe_filter recipe_filter_by_component(const itype_id &c)
ascii_art_id picture_id
Definition: itype.h:880
constexpr localized_comparator localized_compare
Definition: translations.h:342

References _, armor_fit_info(), BASE_BARTER, BASE_PRICE, BASE_RIGIDITY, cata::flat_set< T, Compare, Data >::begin(), bionic_info(), brewing_results(), brewing_time(), itype::can_use(), charges, conductive(), contents, Character::crafting_inventory(), damage(), debug, DESCRIPTION_ACTIVATABLE_TRANSFORMATION, DESCRIPTION_APPLICABLE_RECIPES, DESCRIPTION_BIONIC_ARMOR_INTERFACE, DESCRIPTION_BREWABLE_DURATION, DESCRIPTION_BREWABLE_PRODUCTS, DESCRIPTION_CONDUCTIVITY, DESCRIPTION_FAULTS, DESCRIPTION_FLAGS, DESCRIPTION_GUNMOD_CONSUMABLE, DESCRIPTION_GUNMOD_DISABLESSIGHTS, DESCRIPTION_HOLSTERS, DESCRIPTION_NOTES, DESCRIPTION_RADIO_ACTIVATION, DESCRIPTION_RADIO_ACTIVATION_CHANNEL, DESCRIPTION_RADIO_ACTIVATION_PROC, DESCRIPTION_RADIOACTIVITY_ALWAYS, DESCRIPTION_RADIOACTIVITY_DAMAGED, DESCRIPTION_RECHARGE_NORELOAD, DESCRIPTION_RECHARGE_UPSCAPABLE, DESCRIPTION_RECHARGE_UPSMODDED, DESCRIPTION_TWOHANDED, item_contents::empty(), cata::flat_set< T, Compare, Data >::end(), enumerate_as_string(), faults, flag_CONDUCTIVE(), flag_CONSUMABLE(), flag_DISABLE_SIGHTS(), flag_FIRE_TWOHAND(), flag_LEAK_ALWAYS(), flag_LEAK_DAM(), flag_NO_RELOAD(), flag_RADIO_ACTIVATION(), flag_RADIO_INVOKE_PROC(), flag_RADIO_MOD(), flag_RADIOACTIVE(), flag_RADIOSIGNAL_1(), flag_RADIOSIGNAL_2(), flag_RADIOSIGNAL_3(), flag_RECHARGE(), flag_USE_UPS(), flag_USES_BIONIC_POWER(), time_duration::from_turns(), item_contents::front(), inscribe_actor::gerund, json_flag::get(), use_function::get_actor_ptr(), player::get_available_recipes(), get_avatar(), get_flags(), itype::get_flags(), itype::get_use(), get_var(), has_flag(), has_own_flag(), Character::has_trait(), json_flag::info(), info(), insert_separation_line(), is_armor(), is_brewable(), iteminfo::is_decimal, is_gun(), is_gunmod(), is_null(), is_power_armor(), is_tool(), item_controller, item_vars, itype_id, localized_compare, iteminfo::lower_is_better, made_of(), nname(), iteminfo::no_newline, recipe_subset::of_component(), pgettext(), price(), ptr(), recipe_filter_by_component(), itype::rigid, sign::space, string_format(), iteminfo_query::test(), time, delayed_transform_iuse::time_to_do(), tname(), to_string_clipped(), trait_WOOLALLERGY, iexamine::transform(), type, typeId(), itype::use_methods, and vgettext().

Referenced by info().

◆ find_armor_data()

const islot_armor * item::find_armor_data ( ) const

If this is an armor item, return its armor data.

You should probably not use this function, use the various functions above (like get_storage) to access armor data directly.

Definition at line 6708 of file item.cpp.

6709{
6710 if( type->armor ) {
6711 return &*type->armor;
6712 }
6713 // Currently the only way to make a non-armor item into armor is to install a gun mod.
6714 // The gunmods are stored in the items contents, as are the contents of a container, and the
6715 // tools in a tool belt (a container actually), or the ammo in a quiver (container again).
6716 for( const item *mod : gunmods() ) {
6717 if( mod->type->armor ) {
6718 return &*mod->type->armor;
6719 }
6720 }
6721 return nullptr;
6722}
cata::value_ptr< islot_armor > armor
Definition: itype.h:823

References itype::armor, gunmods(), and type.

Referenced by get_base_env_resist(), get_base_env_resist_w_filter(), get_coverage(), get_covered_body_parts(), get_encumber(), get_encumber_when_containing(), get_env_resist(), get_storage(), get_thickness(), get_warmth(), get_weight_capacity_bonus(), get_weight_capacity_modifier(), is_armor(), and is_sided().

◆ fire_resist()

int item::fire_resist ( bool  to_self = false,
int  base_env_resist = 0 
) const

Definition at line 6187 of file item.cpp.

6188{
6189 if( to_self ) {
6190 // Fire damages items in a different way
6191 return INT_MAX;
6192 }
6193
6194 float resist = 0.0;
6196 if( is_null() ) {
6197 return 0.0;
6198 }
6199
6200 const std::vector<const material_type *> mat_types = made_of_types();
6201 if( !mat_types.empty() ) {
6202 for( const material_type *mat : mat_types ) {
6203 resist += mat->fire_resist();
6204 }
6205 // Average based on number of materials.
6206 resist /= mat_types.size();
6207 }
6208
6209 const int env = get_env_resist( base_env_resist );
6210 if( env < 10 ) {
6211 // Iron resists immersion in magma, iron-clad knight won't.
6212 resist *= env / 10.0f;
6213 }
6214
6215 return std::lround( resist + mod );
6216}
@ clothing_mod_type_fire
Definition: clothing_mod.h:18

References clothing_mod_type_fire, get_clothing_mod_val(), get_env_resist(), is_null(), and made_of_types().

Referenced by armor_inventory_preset::armor_inventory_preset(), armor_protection_info(), anonymous_namespace{armor_layers.cpp}::clothing_protection(), damage_resist(), and sew_advanced_actor::use().

◆ flammable()

bool item::flammable ( int  threshold = 0) const

Whether the items is flammable.

(Make sure to keep this in sync with fire code in fields.cpp)

Parameters
thresholdItem is flammable if it provides more fuel than threshold.

Definition at line 8338 of file item.cpp.

8339{
8340 const std::vector<const material_type *> &mats = made_of_types();
8341 if( mats.empty() ) {
8342 // Don't know how to burn down something made of nothing.
8343 return false;
8344 }
8345
8346 int flammability = 0;
8347 units::volume volume_per_turn = 0_ml;
8348 for( const material_type *m : mats ) {
8349 const mat_burn_data &bd = m->burn_data( 1 );
8350 if( bd.immune ) {
8351 // Made to protect from fire
8352 return false;
8353 }
8354
8355 flammability += bd.fuel;
8356 volume_per_turn += bd.volume_per_turn;
8357 }
8358
8359 if( threshold == 0 || flammability <= 0 ) {
8360 return flammability > 0;
8361 }
8362
8363 volume_per_turn /= mats.size();
8364 units::volume vol = base_volume();
8365 if( volume_per_turn > 0_ml && volume_per_turn < vol ) {
8366 flammability = flammability * volume_per_turn / vol;
8367 } else {
8368 // If it burns well, it provides a bonus here
8369 flammability *= vol / units::legacy_volume_factor;
8370 }
8371
8372 return flammability > threshold;
8373}
Contains burning parameters for a given material.
Definition: fire.h:46
bool immune
If this is true, an object will not burn or be destroyed by fire.
Definition: fire.h:48
units::volume volume_per_turn
If non-zero and lower than item's volume, scale burning by volume_penalty / volume.
Definition: fire.h:50
float fuel
Fuel contributed per tick when this material burns.
Definition: fire.h:52

References base_volume(), mat_burn_data::fuel, mat_burn_data::immune, units::legacy_volume_factor, made_of_types(), and mat_burn_data::volume_per_turn.

Referenced by Character::can_feed_furnace_with(), behavior::character_oracle_t::can_make_fire(), and monster::process_turn().

◆ food_info()

void item::food_info ( const item food_item,
std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug,
temperature_flag  temperature 
) const
Survival >=3 allows detection of poisonous food Survival >=5 allows detection of hallucinogenic food

Definition at line 1674 of file item.cpp.

1677{
1678 nutrients min_nutr;
1679 nutrients max_nutr;
1680 avatar &you = get_avatar();
1681
1682 std::string recipe_exemplar = get_var( "recipe_exemplar", "" );
1683 if( recipe_exemplar.empty() ) {
1684 min_nutr = max_nutr = you.compute_effective_nutrients( *food_item );
1685 } else {
1686 std::tie( min_nutr, max_nutr ) =
1687 you.compute_nutrient_range( *food_item, recipe_id( recipe_exemplar ) );
1688 }
1689
1690 bool show_nutr = parts->test( iteminfo_parts::FOOD_NUTRITION ) ||
1692 if( min_nutr != max_nutr && show_nutr ) {
1693 info.emplace_back(
1694 "FOOD", _( "Nutrition will <color_cyan>vary with chosen ingredients</color>." ) );
1695 if( recipe_dict.is_item_on_loop( food_item->typeId() ) ) {
1696 info.emplace_back(
1697 "FOOD", _( "Nutrition range cannot be calculated accurately due to "
1698 "<color_red>recipe loops</color>." ) );
1699 }
1700 }
1701
1702 const std::string space = " ";
1703 if( max_nutr.kcal != 0 || food_item->get_comestible()->quench != 0 ) {
1704 if( parts->test( iteminfo_parts::FOOD_NUTRITION ) ) {
1705 info.push_back( iteminfo( "FOOD", _( "<bold>Calories (kcal)</bold>: " ),
1706 "", iteminfo::no_newline, min_nutr.kcal ) );
1707 if( max_nutr.kcal != min_nutr.kcal ) {
1708 info.push_back( iteminfo( "FOOD", _( "-" ),
1709 "", iteminfo::no_newline, max_nutr.kcal ) );
1710 }
1711 }
1712 if( parts->test( iteminfo_parts::FOOD_QUENCH ) ) {
1713 info.push_back( iteminfo( "FOOD", space + _( "Quench: " ),
1714 food_item->get_comestible()->quench ) );
1715 }
1716 }
1717
1718 const std::pair<int, int> fun_for_food_item = you.fun_for( *food_item );
1719 if( fun_for_food_item.first != 0 && parts->test( iteminfo_parts::FOOD_JOY ) ) {
1720 info.push_back( iteminfo( "FOOD", _( "Enjoyability: " ), fun_for_food_item.first ) );
1721 }
1722
1723 if( parts->test( iteminfo_parts::FOOD_PORTIONS ) ) {
1724 info.push_back( iteminfo( "FOOD", _( "Portions: " ),
1725 std::abs( static_cast<int>( food_item->charges ) * batch ) ) );
1726 }
1727 if( food_item->corpse != nullptr && parts->test( iteminfo_parts::FOOD_SMELL ) &&
1728 ( debug || ( g != nullptr && ( you.has_trait( trait_CARNIVORE ) ||
1730 info.push_back( iteminfo( "FOOD", _( "Smells like: " ) + food_item->corpse->nname() ) );
1731 }
1732
1733 auto format_vitamin = [&]( const std::pair<vitamin_id, int> &v, bool display_vitamins ) {
1734 const bool is_vitamin = v.first->type() == vitamin_type::VITAMIN;
1735 // only display vitamins that we actually require
1736 if( you.vitamin_rate( v.first ) == 0_turns || v.second == 0 ||
1737 display_vitamins != is_vitamin || v.first->has_flag( flag_NO_DISPLAY ) ) {
1738 return std::string();
1739 }
1740 const double multiplier = you.vitamin_rate( v.first ) / 1_days * 100;
1741 const int min_value = min_nutr.get_vitamin( v.first );
1742 const int max_value = v.second;
1743 const int min_rda = std::lround( min_value * multiplier );
1744 const int max_rda = std::lround( max_value * multiplier );
1745 const std::string format = min_rda == max_rda ? "%s (%i%%)" : "%s (%i-%i%%)";
1746 return string_format( format, v.first->name(), min_value, max_value );
1747 };
1748
1749 const auto max_nutr_vitamins = sorted_lex( max_nutr.vitamins );
1750 const std::string required_vits = enumerate_as_string(
1751 max_nutr_vitamins.begin(),
1752 max_nutr_vitamins.end(),
1753 [&]( const std::pair<vitamin_id, int> &v ) {
1754 return format_vitamin( v, true );
1755 } );
1756
1757 const std::string effect_vits = enumerate_as_string(
1758 max_nutr_vitamins.begin(),
1759 max_nutr_vitamins.end(),
1760 [&]( const std::pair<vitamin_id, int> &v ) {
1761 return format_vitamin( v, false );
1762 } );
1763
1764 if( !required_vits.empty() && parts->test( iteminfo_parts::FOOD_VITAMINS ) ) {
1765 info.emplace_back( "FOOD", _( "Vitamins (RDA): " ), required_vits );
1766 }
1767
1768 if( !effect_vits.empty() && parts->test( iteminfo_parts::FOOD_VIT_EFFECTS ) ) {
1769 info.emplace_back( "FOOD", _( "Other contents: " ), effect_vits );
1770 }
1771
1773
1774 if( you.allergy_type( *food_item ) != morale_type( "morale_null" ) ) {
1775 info.emplace_back( "DESCRIPTION",
1776 _( "* This food will cause an <bad>allergic reaction</bad>." ) );
1777 }
1778
1779 if( food_item->has_flag( flag_CANNIBALISM ) &&
1781 if( !you.has_trait_flag( trait_flag_CANNIBAL ) ) {
1782 info.emplace_back( "DESCRIPTION",
1783 _( "* This food contains <bad>human flesh</bad>." ) );
1784 } else {
1785 info.emplace_back( "DESCRIPTION",
1786 _( "* This food contains <good>human flesh</good>." ) );
1787 }
1788 }
1789
1790 if( food_item->is_tainted() && parts->test( iteminfo_parts::FOOD_CANNIBALISM ) ) {
1791 info.emplace_back( "DESCRIPTION",
1792 _( "* This food is <bad>tainted</bad> and will poison you." ) );
1793 }
1794
1795 ///\EFFECT_SURVIVAL >=3 allows detection of poisonous food
1796 if( food_item->has_flag( flag_HIDDEN_POISON ) && you.get_skill_level( skill_survival ) >= 3 &&
1797 parts->test( iteminfo_parts::FOOD_POISON ) ) {
1798 info.emplace_back( "DESCRIPTION",
1799 _( "* On closer inspection, this appears to be "
1800 "<bad>poisonous</bad>." ) );
1801 }
1802
1803 ///\EFFECT_SURVIVAL >=5 allows detection of hallucinogenic food
1804 if( food_item->has_flag( flag_HIDDEN_HALLU ) && you.get_skill_level( skill_survival ) >= 5 &&
1806 info.emplace_back( "DESCRIPTION",
1807 _( "* On closer inspection, this appears to be "
1808 "<neutral>hallucinogenic</neutral>." ) );
1809 }
1810
1811 if( food_item->goes_bad() && parts->test( iteminfo_parts::FOOD_ROT ) ) {
1812 const std::string rot_time = to_string_clipped( food_item->get_shelf_life() );
1813 info.emplace_back( "DESCRIPTION",
1814 string_format( _( "* This food is <neutral>perishable</neutral>, "
1815 "and at room temperature has an estimated nominal "
1816 "shelf life of <info>%s</info>." ), rot_time ) );
1817
1818
1819 if( parts->test( iteminfo_parts::FOOD_ROT_STORAGE ) ) {
1820 const char *temperature_description;
1821 bool print_freshness_duration = false;
1822 // There should be a better way to do this...
1823 switch( temperature ) {
1826 temperature_description = _( "* Current storage conditions <bad>do not</bad> "
1827 "protect this item from rot." );
1828 }
1829 break;
1832 temperature_description = _( "* Current storage conditions <neutral>partially</neutral> "
1833 "protect this item from rot. It will stay fresh at least <info>%s</info>." );
1834 print_freshness_duration = true;
1835 }
1836 break;
1838 temperature_description = _( "* Current storage conditions <good>fully</good> "
1839 "protect this item from rot. It will stay fresh indefinitely." );
1840 }
1841 break;
1842 default: {
1843 temperature_description = "BUGGED TEMPERATURE INFO";
1844 }
1845 }
1846
1847 if( print_freshness_duration ) {
1848 time_duration remaining_fresh = food_item->minimum_freshness_duration( temperature );
1849 std::string time_string = to_string_clipped( remaining_fresh );
1850 info.emplace_back( "DESCRIPTION", string_format( temperature_description, time_string ) );
1851 } else {
1852 info.emplace_back( "DESCRIPTION", temperature_description );
1853 }
1854 }
1855
1856 if( !food_item->rotten() ) {
1857 info.emplace_back( "DESCRIPTION", get_freshness_description( *food_item ) );
1858 }
1859
1860 if( food_item->has_flag( flag_NO_PARASITES ) ) {
1861 info.emplace_back( "DESCRIPTION",
1862 _( "* It seems that deep freezing <good>killed all "
1863 "parasites</good>." ) );
1864 }
1865 if( food_item->rotten() ) {
1866 if( you.has_bionic( bio_digestion ) ) {
1867 info.push_back( iteminfo( "DESCRIPTION",
1868 _( "This food has started to <neutral>rot</neutral>, "
1869 "but <info>your bionic digestion can tolerate "
1870 "it</info>." ) ) );
1871 } else if( you.has_trait( trait_SAPROVORE ) ) {
1872 info.push_back( iteminfo( "DESCRIPTION",
1873 _( "This food has started to <neutral>rot</neutral>, "
1874 "but <info>you can tolerate it</info>." ) ) );
1875 } else {
1876 info.push_back( iteminfo( "DESCRIPTION",
1877 _( "This food has started to <bad>rot</bad>. "
1878 "<info>Eating</info> it would be a <bad>very bad "
1879 "idea</bad>." ) ) );
1880 }
1881 }
1882 }
1883}
bool has_trait_flag(const std::string &b) const
Returns true if player has a trait with a flag.
Definition: mutation.cpp:106
virtual bool has_artifact_with(art_effect_passive effect) const
Definition: character.cpp:3213
nutrients compute_effective_nutrients(const item &) const
std::pair< nutrients, nutrients > compute_nutrient_range(const item &, const recipe_id &, const cata::flat_set< std::string > &extra_flags={}) const
Get calorie & vitamin contents for a comestible, taking into account character traits.
time_duration vitamin_rate(const vitamin_id &vit) const
Get vitamin usage rate (minutes per unit) accounting for bionics, mutations and effects.
std::pair< int, int > fun_for(const item &comest) const
Handles the enjoyability value for a comestible.
bool rotten() const
returns true if item is now rotten after all shelf life has elapsed
Definition: item.h:849
time_duration minimum_freshness_duration(temperature_flag temperature) const
Time that this item is guaranteed to stay fresh.
Definition: item.cpp:5726
const cata::value_ptr< islot_comestible > & get_comestible() const
Definition: item.cpp:10154
bool is_tainted() const
Is item derived from a zombie?
Definition: item.cpp:9847
bool is_item_on_loop(const itype_id &) const
@ AEP_SUPER_CLAIRVOYANCE
Definition: enums.h:112
static const std::string flag_HIDDEN_POISON("HIDDEN_POISON")
static const std::string flag_NO_DISPLAY("NO_DISPLAY")
static const bionic_id bio_digestion("bio_digestion")
static const trait_id trait_CARNIVORE("CARNIVORE")
static const std::string flag_CANNIBALISM("CANNIBALISM")
static const std::string flag_HIDDEN_HALLU("HIDDEN_HALLU")
static const trait_id trait_SAPROVORE("SAPROVORE")
static const std::string flag_NO_PARASITES("NO_PARASITES")
static const std::string trait_flag_CANNIBAL("CANNIBAL")
static const skill_id skill_survival("survival")
static std::string get_freshness_description(const item &food_item)
Definition: item.cpp:1115
constexpr T max_value()
recipe_dictionary recipe_dict
int kcal
amount of kcal this food has
Definition: stomach.h:18
std::map< vitamin_id, int > vitamins
vitamins potentially provided by this comestible (if any)
Definition: stomach.h:21
int get_vitamin(const vitamin_id &) const
Definition: stomach.cpp:42
string_id< recipe > recipe_id
Definition: type_id.h:143
@ VITAMIN
Definition: vitamin.h:19

References _, AEP_SUPER_CLAIRVOYANCE, Character::allergy_type(), bio_digestion, charges, Character::compute_effective_nutrients(), Character::compute_nutrient_range(), corpse, debug, enumerate_as_string(), flag_CANNIBALISM(), flag_HIDDEN_HALLU(), flag_HIDDEN_POISON(), flag_NO_DISPLAY(), flag_NO_PARASITES(), FOOD_CANNIBALISM, FOOD_HALLUCINOGENIC, FOOD_JOY, FOOD_NUTRITION, FOOD_POISON, FOOD_PORTIONS, FOOD_QUENCH, FOOD_ROT, FOOD_ROT_STORAGE, FOOD_SMELL, FOOD_VIT_EFFECTS, FOOD_VITAMINS, format(), Character::fun_for(), g, get_avatar(), get_comestible(), get_freshness_description(), get_shelf_life(), Character::get_skill_level(), get_var(), nutrients::get_vitamin(), goes_bad(), Character::has_artifact_with(), Character::has_bionic(), has_flag(), Character::has_trait(), Character::has_trait_flag(), info(), insert_separation_line(), recipe_dictionary::is_item_on_loop(), is_tainted(), nutrients::kcal, detail::max_value(), minimum_freshness_duration(), mtype::nname(), iteminfo::no_newline, recipe_dict, rotten(), skill_survival, sorted_lex(), sign::space, string_format(), TEMP_FREEZER, TEMP_FRIDGE, TEMP_HEATER, TEMP_NORMAL, TEMP_ROOT_CELLAR, iteminfo_query::test(), to_string_clipped(), trait_CARNIVORE, trait_flag_CANNIBAL(), trait_SAPROVORE, typeId(), VITAMIN, Character::vitamin_rate(), and nutrients::vitamins.

Referenced by info().

◆ fuel_energy()

float item::fuel_energy ( ) const

Returns energy of one charge of this item as fuel for an engine.

Definition at line 6842 of file item.cpp.

6843{
6844 return is_fuel() ? type->fuel->energy : 0.0f;
6845}
bool is_fuel() const
Definition: item.cpp:6786
cata::value_ptr< islot_fuel > fuel
Definition: itype.h:829

References itype::fuel, is_fuel(), and type.

Referenced by Character::burn_fuel(), vehicle_part::consume_energy(), vehicle::consume_fuel(), vehicle::consumption_per_hour(), Character::get_acquirable_energy(), game::on_move_effects(), and Character::passive_power_gen().

◆ fuel_pump_terrain()

std::string item::fuel_pump_terrain ( ) const

Returns the string of the id of the terrain that pumps this fuel, if any.

Definition at line 6847 of file item.cpp.

6848{
6849 return is_fuel() ? type->fuel->pump_terrain : "t_null";
6850}

References itype::fuel, is_fuel(), and type.

Referenced by map::place_gas_pump().

◆ get_available_recipes()

std::vector< std::pair< const recipe *, int > > item::get_available_recipes ( const player u) const

Enumerates recipes available from this book and the skill level required to use them.

Definition at line 7141 of file item.cpp.

7142{
7143 std::vector<std::pair<const recipe *, int>> recipe_entries;
7144 if( is_book() ) {
7145 for( const islot_book::recipe_with_description_t &elem : type->book->recipes ) {
7146 if( u.get_skill_level( elem.recipe->skill_used ) >= elem.skill_level ) {
7147 recipe_entries.push_back( std::make_pair( elem.recipe, elem.skill_level ) );
7148 }
7149 }
7150 } else if( has_var( "EIPC_RECIPES" ) ) {
7151 // See einkpc_download_memory_card() in iuse.cpp where this is set.
7152 const std::string recipes = get_var( "EIPC_RECIPES" );
7153 // Capture the index one past the delimiter, i.e. start of target string.
7154 size_t first_string_index = recipes.find_first_of( ',' ) + 1;
7155 while( first_string_index != std::string::npos ) {
7156 size_t next_string_index = recipes.find_first_of( ',', first_string_index );
7157 if( next_string_index == std::string::npos ) {
7158 break;
7159 }
7160 std::string new_recipe = recipes.substr( first_string_index,
7161 next_string_index - first_string_index );
7162 const recipe *r = &recipe_id( new_recipe ).obj();
7163 if( u.get_skill_level( r->skill_used ) >= r->difficulty ) {
7164 recipe_entries.push_back( std::make_pair( r, r->difficulty ) );
7165 }
7166 first_string_index = next_string_index + 1;
7167 }
7168 }
7169 return recipe_entries;
7170}
int difficulty
Definition: recipe.h:62

References itype::book, recipe::difficulty, Character::get_skill_level(), get_var(), has_var(), is_book(), string_id< T >::obj(), islot_book::recipe_with_description_t::recipe, islot_book::recipe_with_description_t::skill_level, recipe::skill_used, and type.

Referenced by avatar::do_read(), and player::get_recipes_from_books().

◆ get_base_env_resist_w_filter()

int item::get_base_env_resist_w_filter ( ) const

Returns the base resistance to environmental effects if an item (for example a gas mask) requires a gas filter to operate and this filter is installed.

Used in iuse::gasmask to change protection of a gas mask if it has (or don't has) filters. For other applications use get_env_resist() above.

Definition at line 5803 of file item.cpp.

5804{
5805 const islot_armor *t = find_armor_data();
5806 if( t == nullptr ) {
5807 return is_pet_armor() ? type->pet_armor->env_resist_w_filter : 0;
5808 }
5809 return t->env_resist_w_filter;
5810}
const islot_armor * find_armor_data() const
If this is an armor item, return its armor data.
Definition: item.cpp:6708
int env_resist_w_filter
Environmental protection of a gas mask with installed filter.
Definition: itype.h:268
cata::value_ptr< islot_pet_armor > pet_armor
Definition: itype.h:824

References islot_armor::env_resist_w_filter, find_armor_data(), is_pet_armor(), itype::pet_armor, and type.

Referenced by armor_protection_info(), iuse::dive_tank(), and iuse::gasmask().

◆ get_base_material()

const material_type & item::get_base_material ( ) const

Get the basic (main) material of this item.

May return the null-material.

Definition at line 7177 of file item.cpp.

7178{
7179 const std::vector<material_id> &mats = made_of();
7180 return mats.empty() ? material_id::NULL_ID().obj() : mats.front().obj();
7181}

References made_of(), string_id< material_type >::NULL_ID(), and string_id< T >::obj().

Referenced by Character::armor_absorb(), and durability_indicator().

◆ get_cable_target()

std::optional< tripoint > item::get_cable_target ( Character p,
const tripoint pos 
) const

Gets the point (vehicle tile) the cable is connected to.

Returns nothing if not connected to anything.

Definition at line 9372 of file item.cpp.

9373{
9374 const std::string &state = get_var( "state" );
9375 if( state != "pay_out_cable" && state != "cable_charger_link" ) {
9376 return std::nullopt;
9377 }
9378 map &here = get_map();
9379 const optional_vpart_position vp_pos = here.veh_at( pos );
9380 if( vp_pos ) {
9381 const std::optional<vpart_reference> seat = vp_pos.part_with_feature( "BOARDABLE", true );
9382 if( seat && p == seat->vehicle().get_passenger( seat->part_index() ) ) {
9383 return pos;
9384 }
9385 }
9386
9387 tripoint source( get_var( "source_x", 0 ), get_var( "source_y", 0 ), get_var( "source_z", 0 ) );
9388
9389 return here.getlocal( source );
9390}
Manage and cache data about a part of the map.
Definition: map.h:384
Simple wrapper to forward functions that may return a std::optional to vpart_position.
std::optional< vpart_reference > part_with_feature(const std::string &f, bool unbroken) const
Definition: vehicle.cpp:2483
auto here(const Character &you) -> elevator::tiles

References get_map(), get_var(), anonymous_namespace{iexamine_elevator.cpp}::elevator::here(), and optional_vpart_position::part_with_feature().

Referenced by process_cable().

◆ get_cached_tool_selections()

const std::vector< comp_selection< tool_comp > > & item::get_cached_tool_selections ( ) const

Definition at line 10148 of file item.cpp.

10149{
10150 assert( craft_data_ );
10151 return craft_data_->cached_tool_selections;
10152}

References craft_data_.

◆ get_category()

const item_category & item::get_category ( ) const

Definition at line 8708 of file item.cpp.

8709{
8710 if( is_container() && !contents.empty() ) {
8711 return contents.front().get_category();
8712 }
8713
8714 static item_category null_category;
8715 return type->category_force.is_valid() ? type->category_force.obj() : null_category;
8716}
Contains metadata for one category of items.
Definition: item_category.h:35
item_category_id category_force
If set via JSON forces item category to this (preventing automatic assignment)
Definition: itype.h:974

References itype::category_force, contents, item_contents::empty(), item_contents::front(), get_category(), is_container(), string_id< T >::is_valid(), string_id< T >::obj(), and type.

Referenced by inventory_selector::add_items(), basic_info(), json_talk_topic::gen_responses(), get_category(), inventory_entry::get_category_ptr(), zone_manager::get_near_zone_type_for_item(), is_map(), map_item_stack::map_item_stack_sort(), operator<(), conditional_t< T >::set_has_item_category(), and spoilage_sort_order().

◆ get_chapters()

int item::get_chapters ( ) const

How many chapters the book has (if any).

Will be 0 if the item is not a book, or if it has no chapters at all. Each reading will "consume" a chapter, if the book has no unread chapters, it's less fun.

Definition at line 7115 of file item.cpp.

7116{
7117 if( !type->book ) {
7118 return 0;
7119 }
7120 return type->book->chapters;
7121}

References itype::book, and type.

Referenced by display_name(), character_funcs::get_book_fun_for(), get_remaining_chapters(), and io().

◆ get_clothing_mod_val()

float item::get_clothing_mod_val ( clothing_mod_type  type) const

Definition at line 10190 of file item.cpp.

10191{
10192 return get_var( get_clothing_mod_val_key( type ), 0.0f );
10193}
const std::string & get_clothing_mod_val_key(clothing_mod_type type)
Definition: item.cpp:10175

References anonymous_namespace{item.cpp}::get_clothing_mod_val_key(), get_var(), and type.

Referenced by acid_resist(), bash_resist(), bullet_resist(), cut_resist(), fire_resist(), get_encumber_when_containing(), get_storage(), and get_warmth().

◆ get_comestible()

◆ get_comestible_fun()

int item::get_comestible_fun ( ) const

Definition at line 5508 of file item.cpp.

5509{
5510 if( !is_comestible() ) {
5511 return 0;
5512 }
5513 int fun = get_comestible()->fun;
5514 for( const std::string &flag : item_tags ) {
5515 fun += json_flag::get( flag ).taste_mod();
5516 }
5517 for( const std::string &flag : type->get_flags() ) {
5518 fun += json_flag::get( flag ).taste_mod();
5519 }
5520
5521 return fun;
5522}
bool is_comestible() const
Definition: item.cpp:6613
int taste_mod() const
The flag's modifier on the fun value of comestibles.
Definition: flag.h:55

References json_flag::get(), get_comestible(), itype::get_flags(), is_comestible(), item_tags, json_flag::taste_mod(), and type.

Referenced by iuse::blech(), basecamp::distribute_food(), mattack::eat_food(), Character::fun_for(), med_info(), rate_food(), and npc::will_accept_from_player().

◆ get_contained()

const item & item::get_contained ( ) const

Return a contained item (if any and only one).

Definition at line 7077 of file item.cpp.

7078{
7079 if( contents.empty() ) {
7080 return null_item_reference();
7081 }
7082 return contents.front();
7083}
item & null_item_reference()
Returns a reference to a null item (see item::is_null).
Definition: item.cpp:326

References contents, item_contents::empty(), item_contents::front(), and null_item_reference().

Referenced by Character::consume_effects(), basecamp::distribute_food(), trading_window::get_var_trade(), Character::invoke_item(), examine_item_menu::rate_action_use(), ranged::throw_item(), try_consume(), avatar_funcs::use_item(), avatar::wield(), avatar_action::wield(), npc::wield_better_weapon(), and npc::will_accept_from_player().

◆ get_container_capacity()

units::volume item::get_container_capacity ( ) const

It returns the total capacity (volume) of the container for liquids.

Definition at line 8418 of file item.cpp.

8419{
8420 if( !is_container() ) {
8421 return 0_ml;
8422 }
8423 return type->container->contains;
8424}

References itype::container, is_container(), and type.

Referenced by vehicle_part::ammo_capacity(), display_name(), get_remaining_capacity_for_liquid(), get_total_capacity(), is_funnel_container(), Item_factory::migrate_item(), Item_modifier::modify(), and ranged::throw_item().

◆ get_continue_reqs()

requirement_data item::get_continue_reqs ( ) const

Returns requirement data representing what is needed to resume work on an in progress craft.

Causes a debugmsg and returns empty requirement data if called on a non-craft

Returns
what is needed to continue craft, may be empty requirement data

Definition at line 976 of file crafting.cpp.

977{
978 if( !is_craft() ) {
979 debugmsg( "get_continue_reqs() called on non-craft '%s.' Aborting.", tname() );
980 return requirement_data();
981 }
983}
static requirement_data continue_requirements(const std::vector< item_comp > &required_comps, const std::list< item > &remaining_comps)
Returns the item requirements to continue an in progress craft with the passed components.

References components, requirement_data::continue_requirements(), craft_data_, debugmsg, is_craft(), and tname().

◆ get_corpse_name()

std::string item::get_corpse_name ( )

Returns name of deceased being if it had any or empty string if not.

Definition at line 9944 of file item.cpp.

9945{
9946 if( corpse_name.empty() ) {
9947 return std::string();
9948 }
9949 return corpse_name;
9950}
std::string corpse_name
Definition: item.h:2183

References corpse_name.

◆ get_coverage()

int item::get_coverage ( ) const

Returns the relative coverage that this item has when worn.

Values range from 0 (not covering anything, or no armor at all) to 100 (covering the whole body part). Items that cover more are more likely to absorb damage from attacks.

Definition at line 5926 of file item.cpp.

5927{
5928 const islot_armor *t = find_armor_data();
5929 if( t == nullptr ) {
5930 return 0;
5931 }
5932 return t->coverage;
5933}
int coverage
Percentage of the body part area that this item covers.
Definition: itype.h:256

References islot_armor::coverage, and find_armor_data().

Referenced by Character::armor_absorb(), armor_info(), armor_inventory_preset::armor_inventory_preset(), Character::block_ranged_hit(), relic_funcs::check_recharge_reqs(), anonymous_namespace{armor_layers.cpp}::clothing_properties(), clothing_mod::get_mod_val(), character_funcs::is_bp_immune_to(), map::player_in_field(), tutorial_game::post_action(), wind_resistance_from_item_list(), and mdefense::zapback().

◆ get_covered_body_parts() [1/2]

body_part_set item::get_covered_body_parts ( ) const

Bitset of all covered body parts.

If the bit is set, the body part is covered by this item (when worn). The index of the bit should be a body part, for example:

if( some_armor.get_covered_body_parts().test( bp_head ) ) { ... }

For testing only a single body part, use covers instead. This function allows you to get the whole covering data in one call.

Definition at line 757 of file item.cpp.

758{
760}

References get_covered_body_parts(), and get_side().

Referenced by npc::adjust_worn(), Character::armor_absorb(), armor_info(), Character::can_swap(), Character::can_wear(), covers(), get_covered_body_parts(), layer_item(), on_wear(), player_morale::on_worn_item_washed(), player_morale::set_worn(), and weather_effect::wet_player().

◆ get_covered_body_parts() [2/2]

body_part_set item::get_covered_body_parts ( side  s) const

Bitset of all covered body parts, from a specific side.

If the bit is set, the body part is covered by this item (when worn). The index of the bit should be a body part, for example:

if( some_armor.get_covered_body_parts().test( bp_head ) ) { ... }

For testing only a single body part, use covers instead. This function allows you to get the whole covering data in one call.

Parameters
sSpecifies the side. Will be ignored for non-sided items.

Definition at line 762 of file item.cpp.

763{
764 body_part_set res;
765
766 if( is_gun() ) {
767 // Currently only used for guns with the should strap mod, other guns might
768 // go on another bodypart.
769 res.set( bp_torso );
770 }
771
772 const islot_armor *armor = find_armor_data();
773 if( armor == nullptr ) {
774 return res;
775 }
776
777 res |= armor->covers;
778
779 if( !armor->sided ) {
780 return res; // Just ignore the side.
781 }
782
783 switch( s ) {
784 case side::BOTH:
785 case side::num_sides:
786 break;
787
788 case side::LEFT:
789 res.reset( bp_arm_r );
790 res.reset( bp_hand_r );
791 res.reset( bp_leg_r );
792 res.reset( bp_foot_r );
793 break;
794
795 case side::RIGHT:
796 res.reset( bp_arm_l );
797 res.reset( bp_hand_l );
798 res.reset( bp_leg_l );
799 res.reset( bp_foot_l );
800 break;
801 }
802
803 return res;
804}
void set(const body_part &bp)
Definition: bodypart.h:256
void reset()
Definition: bodypart.h:259
bool sided
Whether this item can be worn on either side of the body.
Definition: itype.h:243
body_part_set covers
Bitfield of enum body_part TODO: document me.
Definition: itype.h:239

References BOTH, bp_arm_l, bp_arm_r, bp_foot_l, bp_foot_r, bp_hand_l, bp_hand_r, bp_leg_l, bp_leg_r, bp_torso, islot_armor::covers, find_armor_data(), is_gun(), LEFT, num_sides, body_part_set::reset(), RIGHT, body_part_set::set(), and islot_armor::sided.

◆ get_enchantments()

const std::vector< enchantment > & item::get_enchantments ( ) const

Definition at line 7004 of file item.cpp.

7005{
7006 if( !is_relic() ) {
7007 static const std::vector<enchantment> fallback;
7008 return fallback;
7009 }
7010 return relic_data->get_enchantments();
7011}
bool is_relic() const
Definition: item.cpp:6999

References is_relic(), and relic_data.

Referenced by bonus_from_enchantments(), bonus_from_enchantments_wielded(), process_relic(), and Character::recalculate_enchantment_cache().

◆ get_encumber()

int item::get_encumber ( const Character p) const

Returns the encumbrance value that this item has when worn by given player.

Returns 0 if this is can not be worn at all.

Definition at line 5818 of file item.cpp.

5819{
5820
5821 units::volume contents_volume( 0_ml );
5822
5823 contents_volume += contents.item_size_modifier();
5824
5825 if( p.is_worn( *this ) ) {
5826 const islot_armor *t = find_armor_data();
5827
5828 if( t != nullptr && t->max_encumber != 0 ) {
5829 units::volume char_storage( 0_ml );
5830
5831 for( const item &e : p.worn ) {
5832 char_storage += e.get_storage();
5833 }
5834
5835 if( char_storage != 0_ml ) {
5836 // Cast up to 64 to prevent overflow. Dividing before would prevent this but lose data.
5837 contents_volume += units::from_milliliter( static_cast<int64_t>( t->storage.value() ) *
5838 p.inv.volume().value() / char_storage.value() );
5839 }
5840 }
5841 }
5842
5843 return get_encumber_when_containing( p, contents_volume );
5844}
inventory inv
Definition: character.h:1581
std::list< item > worn
Definition: character.h:1569
bool is_worn(const item &thing) const
Definition: character.h:1099
units::volume volume() const
Definition: inventory.cpp:1061
units::volume item_size_modifier() const
constexpr quantity< value_type, volume_in_milliliter_tag > from_milliliter(const value_type v)
Definition: units_volume.h:25
int max_encumber
When storage is full, how much it encumbers the player.
Definition: itype.h:251
units::volume storage
How much storage this items provides when worn.
Definition: itype.h:276

References contents, find_armor_data(), units::from_milliliter(), get_encumber_when_containing(), get_storage(), Character::inv, Character::is_worn(), item_contents::item_size_modifier(), islot_armor::max_encumber, islot_armor::storage, units::quantity< V, U >::value(), inventory::volume(), and Character::worn.

Referenced by armor_fit_info(), armor_info(), armor_inventory_preset::armor_inventory_preset(), repair_item_actor::can_repair_target(), Character::can_wear(), anonymous_namespace{armor_layers.cpp}::clothing_properties(), repair_item_actor::default_action(), Character::head_cloth_encumbrance(), Character::item_wear_cost(), layer_item(), tname(), and sew_advanced_actor::use().

◆ get_encumber_when_containing()

int item::get_encumber_when_containing ( const Character p,
const units::volume contents_volume 
) const

Returns the encumbrance value that this item has when worn by given player, when containing a particular volume of contents.

Returns 0 if this can not be worn at all.

Definition at line 5846 of file item.cpp.

5848{
5849 const islot_armor *t = find_armor_data();
5850 if( t == nullptr ) {
5851 // handle wearable guns (e.g. shoulder strap) as special case
5852 return is_gun() ? volume() / 750_ml : 0;
5853 }
5854 int encumber = t->encumber;
5855
5856 // Non-rigid items add additional encumbrance proportional to their volume
5857 if( !type->rigid ) {
5858 const int capacity = get_total_capacity().value();
5859
5860 if( t->max_encumber != 0 ) {
5861
5862 if( capacity > 0 ) {
5863 // Cast up to 64 to prevent overflow. Dividing before would prevent this but lose data.
5864 encumber += static_cast<int64_t>( t->max_encumber - t->encumber ) * contents_volume.value() /
5865 capacity;
5866 } else {
5867 debugmsg( "Non-rigid item (%s) without storage capacity.", tname() );
5868 }
5869 } else {
5870 encumber += contents_volume / 500_ml;
5871 }
5872 }
5873
5874 // Fit checked before changes, fitting shouldn't reduce penalties from patching.
5875 if( has_flag( flag_FIT ) && has_flag( flag_VARSIZE ) ) {
5876 encumber = std::max( encumber / 2, encumber - 10 );
5877 }
5878
5879 // TODO: Should probably have sizing affect coverage
5880 const sizing sizing_level = get_sizing( p, encumber != 0 );
5881 switch( sizing_level ) {
5884 // non small characters have a HARD time wearing undersized clothing
5885 encumber *= 3;
5886 break;
5889 // clothes bag up around smol characters and encumber them more
5890 encumber *= 2;
5891 break;
5892 default:
5893 break;
5894 }
5895
5896 encumber += static_cast<int>( std::ceil( get_clothing_mod_val( clothing_mod_type_encumbrance ) ) );
5897
5898 return encumber;
5899}
@ clothing_mod_type_encumbrance
Definition: clothing_mod.h:22
int encumber
How much this item encumbers the player.
Definition: itype.h:247

References big_sized_small_char, clothing_mod_type_encumbrance, debugmsg, islot_armor::encumber, find_armor_data(), flag_FIT(), flag_VARSIZE(), get_clothing_mod_val(), get_sizing(), get_total_capacity(), has_flag(), human_sized_small_char, is_gun(), islot_armor::max_encumber, itype::rigid, small_sized_big_char, small_sized_human_char, tname(), type, units::quantity< V, U >::value(), and volume().

Referenced by armor_info(), and get_encumber().

◆ get_env_resist()

int item::get_env_resist ( int  override_base_resist = 0) const

Returns the resistance to environmental effects (islot_armor::env_resist) that this item provides when worn.

See player::get_env_resist. Higher values are better. For non-armor it returns 0.

Parameters
override_base_resistPass this to artifically increase the base resistance, so that the function can take care of other modifications to resistance for you. Note that this parameter will never decrease base resistnace.

Definition at line 5789 of file item.cpp.

5790{
5791 const islot_armor *t = find_armor_data();
5792 if( t == nullptr ) {
5793 return is_pet_armor() ? type->pet_armor->env_resist : 0;
5794 }
5795 // modify if item is a gas mask and has filter
5796 int resist_base = t->env_resist;
5797 int resist_filter = get_var( "overwrite_env_resist", 0 );
5798 int resist = std::max( { resist_base, resist_filter, override_base_resist } );
5799
5800 return std::lround( resist * get_relative_health() );
5801}
float get_relative_health() const
Relative item health.
Definition: item.cpp:6247
int env_resist
Resistance to environmental effects.
Definition: itype.h:264

References islot_armor::env_resist, find_armor_data(), get_relative_health(), get_var(), is_pet_armor(), itype::pet_armor, and type.

Referenced by acid_resist(), armor_inventory_preset::armor_inventory_preset(), armor_protection_info(), anonymous_namespace{armor_layers.cpp}::clothing_protection(), fire_resist(), and tutorial_game::post_action().

◆ get_explosion_data()

struct fuel_explosion item::get_explosion_data ( )

Definition at line 6857 of file item.cpp.

6858{
6859 static struct fuel_explosion null_data;
6860 return has_explosion_data() ? type->fuel->explosion_data : null_data;
6861}
bool has_explosion_data() const
Definition: item.cpp:6852

References type.

Referenced by vehicle::explode_fuel().

◆ get_flags()

const item::FlagsSetType & item::get_flags ( ) const

returs read-only set of flags of this item (not including flags from item type or gunmods)

Definition at line 5379 of file item.cpp.

5380{
5381 return item_tags;
5382}

References item_tags.

Referenced by final_info().

◆ get_food() [1/2]

item * item::get_food ( )

Definition at line 6668 of file item.cpp.

6669{
6670 return get_food_impl( this );
6671}
static Item * get_food_impl(Item *it)
Definition: item.cpp:6657

References get_food_impl().

Referenced by basic_info(), color_in_inventory(), npc::consume_food(), npc::decide_needs(), zone_manager::get_near_zone_type_for_item(), and info().

◆ get_food() [2/2]

const item * item::get_food ( ) const

Definition at line 6673 of file item.cpp.

6674{
6675 return get_food_impl( this );
6676}

References get_food_impl().

◆ get_free_mod_locations()

int item::get_free_mod_locations ( const gunmod_location location) const

Number of mods that can still be installed into the given mod location, for non-guns it always returns 0.

Definition at line 4116 of file item.cpp.

4117{
4118 if( !is_gun() ) {
4119 return 0;
4120 }
4121
4122 std::map<gunmod_location, int> mod_locations = get_mod_locations();
4123
4124 const auto loc = mod_locations.find( location );
4125 if( loc == mod_locations.end() ) {
4126 return 0;
4127 }
4128 int result = loc->second;
4129 for( const item *elem : contents.all_items_top() ) {
4130 const cata::value_ptr<islot_gunmod> &mod = elem->type->gunmod;
4131 if( mod && mod->location == location ) {
4132 result--;
4133 }
4134 }
4135 return result;
4136}
This class is essentially a copyable unique pointer.
Definition: value_ptr.h:19
std::map< gunmod_location, int > get_mod_locations() const
Get mod locations, including those added by other mods.
Definition: item.cpp:4099

References item_contents::all_items_top(), contents, get_mod_locations(), and is_gun().

Referenced by saw_stock_actor::can_use_on(), gun_info(), avatar_funcs::gunmod_remove(), and is_gunmod_compatible().

◆ get_gun_ups_drain()

int item::get_gun_ups_drain ( ) const

Definition at line 9962 of file item.cpp.

9963{
9964 int draincount = 0;
9965 if( type->gun ) {
9966 int modifier = 0;
9967 float multiplier = 1.0f;
9968 for( const item *mod : gunmods() ) {
9969 modifier += mod->type->gunmod->ups_charges_modifier;
9970 multiplier *= mod->type->gunmod->ups_charges_multiplier;
9971 }
9972 draincount = ( type->gun->ups_charges * multiplier ) + modifier;
9973 }
9974 return draincount;
9975}

References itype::gun, gunmods(), and type.

Referenced by character_funcs::ammo_count_for(), npc::decide_needs(), ranged::fire_gun(), ranged::gunmode_checks_weapon(), turret_data::query(), item_funcs::shots_remaining(), and target_ui::update_ammo_range_from_gun_mode().

◆ get_layer()

layer_level item::get_layer ( ) const

Returns clothing layer for item.

Definition at line 5901 of file item.cpp.

5902{
5903 if( type->armor ) {
5904 // We assume that an item will never have per-item flags defining its
5905 // layer, so we can defer to the itype.
5906 return type->layer;
5907 }
5908
5909 if( has_flag( flag_PERSONAL ) ) {
5910 return PERSONAL_LAYER;
5911 } else if( has_flag( flag_SKINTIGHT ) ) {
5912 return UNDERWEAR_LAYER;
5913 } else if( has_flag( flag_WAIST ) ) {
5914 return WAIST_LAYER;
5915 } else if( has_flag( flag_OUTER ) ) {
5916 return OUTER_LAYER;
5917 } else if( has_flag( flag_BELTED ) ) {
5918 return BELTED_LAYER;
5919 } else if( has_flag( flag_AURA ) ) {
5920 return AURA_LAYER;
5921 } else {
5922 return REGULAR_LAYER;
5923 }
5924}
@ WAIST_LAYER
Definition: enums.h:222
@ UNDERWEAR_LAYER
Definition: enums.h:218
@ REGULAR_LAYER
Definition: enums.h:220
@ BELTED_LAYER
Definition: enums.h:226
@ PERSONAL_LAYER
Definition: enums.h:216
@ AURA_LAYER
Definition: enums.h:228
@ OUTER_LAYER
Definition: enums.h:224
layer_level layer
Definition: itype.h:999

References itype::armor, AURA_LAYER, BELTED_LAYER, flag_AURA(), flag_BELTED(), flag_OUTER(), flag_PERSONAL(), flag_SKINTIGHT(), flag_WAIST(), has_flag(), itype::layer, OUTER_LAYER, PERSONAL_LAYER, REGULAR_LAYER, type, UNDERWEAR_LAYER, and WAIST_LAYER.

Referenced by Character::item_wear_cost(), profession::items(), and layer_item().

◆ get_making()

const recipe & item::get_making ( ) const

Get the stored recipe for in progress crafts.

Causes a debugmsg if called on a non-craft and returns the null recipe.

Returns
the recipe in progress

Definition at line 10119 of file item.cpp.

10120{
10121 if( !craft_data_ ) {
10122 debugmsg( "'%s' is not a craft or has a null recipe", tname() );
10123 static const recipe dummy{};
10124 return dummy;
10125 }
10126 assert( craft_data_->making );
10127 return *craft_data_->making;
10128}

References craft_data_, debugmsg, and tname().

Referenced by iuse::craft(), handle_craft_failure(), and set_next_failure_point().

◆ get_min_str()

int item::get_min_str ( ) const

Definition at line 10074 of file item.cpp.

10075{
10076 if( type->gun ) {
10077 int min_str = type->min_str;
10078 for( const item *mod : gunmods() ) {
10079 min_str += mod->type->gunmod->min_str_required_mod;
10080 }
10081 return min_str > 0 ? min_str : 0;
10082 } else {
10083 return type->min_str;
10084 }
10085}
int min_str
Definition: itype.h:908

References itype::gun, gunmods(), itype::min_str, and type.

Referenced by basic_info(), Character::enumerate_unmet_requirements(), ranged::get_str_draw_penalty(), aim_activity_actor::load_RAS_weapon(), Character::meets_stat_requirements(), ranged::str_draw_damage_modifier(), ranged::str_draw_dispersion_modifier(), and ranged::str_draw_range_modifier().

◆ get_mod_locations()

std::map< gunmod_location, int > item::get_mod_locations ( ) const

Get mod locations, including those added by other mods.

Definition at line 4099 of file item.cpp.

4100{
4101 std::map<gunmod_location, int> mod_locations = type->gun->valid_mod_locations;
4102
4103 for( const item *mod : gunmods() ) {
4104 if( !mod->type->gunmod->add_mod.empty() ) {
4105 std::map<gunmod_location, int> add_locations = mod->type->gunmod->add_mod;
4106
4107 for( const std::pair<const gunmod_location, int> &add_location : add_locations ) {
4108 mod_locations[add_location.first] += add_location.second;
4109 }
4110 }
4111 }
4112
4113 return mod_locations;
4114}

References itype::gun, gunmods(), and type.

Referenced by get_free_mod_locations(), gun_info(), avatar_funcs::gunmod_remove(), and is_gunmod_compatible().

◆ get_mtype()

const mtype * item::get_mtype ( ) const
Returns
The monster type associated with this item (corpse). It is usually the type that this item is made of (e.g. corpse, meat or blood of the monster). May return a null-pointer.

Definition at line 6651 of file item.cpp.

6652{
6653 return corpse;
6654}

References corpse.

Referenced by computer_session::action_blood_anal(), burn(), activity_handlers::butcher_finish(), butcher_time_to_cut(), butchery_drops_harvest(), butchery_quarter(), consider_butchery(), editmap::draw_main_ui_overlay(), and game::revive_corpse().

◆ get_next_failure_point()

int item::get_next_failure_point ( ) const

Get the failure point stored in this item.

returns INT_MAX if the failure point is unset. Causes a debugmsg and returns INT_MAX if called on a non-craft.

Returns
an integer >= 0 representing a percent to 5 decimal places. 67.32 percent would be represented as 6732000

Definition at line 896 of file crafting.cpp.

897{
898 if( !is_craft() ) {
899 debugmsg( "get_next_failure_point() called on non-craft '%s.' Aborting.", tname() );
900 return INT_MAX;
901 }
902 return craft_data_->next_failure_point >= 0 ? craft_data_->next_failure_point : INT_MAX;
903}

References craft_data_, debugmsg, is_craft(), and tname().

◆ get_old_owner()

faction_id item::get_old_owner ( ) const

Definition at line 1289 of file item.cpp.

1290{
1292 return old_owner;
1293}
faction_id old_owner
Definition: item.h:2241
void validate_ownership() const
Definition: item.cpp:1295

References old_owner, and validate_ownership().

Referenced by is_old_owner().

◆ get_owner()

faction_id item::get_owner ( ) const

Definition at line 1283 of file item.cpp.

1284{
1286 return owner;
1287}

References owner, and validate_ownership().

Referenced by get_owner_name(), handle_pickup_ownership(), is_owned_by(), and query_consume_ownership().

◆ get_owner_name()

std::string item::get_owner_name ( ) const

Definition at line 1265 of file item.cpp.

1266{
1267 if( !g->faction_manager_ptr->get( get_owner() ) ) {
1268 debugmsg( "item::get_owner_name() item %s has no valid nor null faction id ", tname() );
1269 return "no owner";
1270 }
1271 return g->faction_manager_ptr->get( get_owner() )->name;
1272}
faction_id get_owner() const
Definition: item.cpp:1283

References debugmsg, g, get_owner(), and tname().

Referenced by basic_info().

◆ get_pet_armor_bodytype()

std::string item::get_pet_armor_bodytype ( ) const

Definition at line 5967 of file item.cpp.

5968{
5969 return is_pet_armor() ? type->pet_armor->bodytype : "";
5970}

References is_pet_armor(), itype::pet_armor, and type.

◆ get_pet_armor_max_vol()

units::volume item::get_pet_armor_max_vol ( ) const

Definition at line 5957 of file item.cpp.

5958{
5959 return is_pet_armor() ? type->pet_armor->max_vol : 0_ml;
5960}

References is_pet_armor(), itype::pet_armor, and type.

◆ get_pet_armor_min_vol()

units::volume item::get_pet_armor_min_vol ( ) const

Definition at line 5962 of file item.cpp.

5963{
5964 return is_pet_armor() ? type->pet_armor->min_vol : 0_ml;
5965}

References is_pet_armor(), itype::pet_armor, and type.

◆ get_plant_epoch()

time_duration item::get_plant_epoch ( ) const

Time it takes to grow from one stage to another.

There are 4 plant stages: seed, seedling, mature and harvest. Non-seed items return 0.

Definition at line 9809 of file item.cpp.

9810{
9811 if( !type->seed ) {
9812 return 0_turns;
9813 }
9814 // Growing times have been based around real world season length rather than
9815 // the default in-game season length to give
9816 // more accuracy for longer season lengths
9817 // Also note that seed->grow is the time it takes from seeding to harvest, this is
9818 // divided by 3 to get the time it takes from one plant state to the next.
9819 // TODO: move this into the islot_seed
9820 return type->seed->grow * calendar::season_ratio() / 3;
9821}
float season_ratio()
Definition: calendar.cpp:485
cata::value_ptr< islot_seed > seed
Definition: itype.h:836

References calendar::season_ratio(), itype::seed, and type.

◆ get_plant_name()

std::string item::get_plant_name ( ) const

The name of the plant as it appears in the various informational menus.

This should be translated. Returns an empty string for non-seed items.

Definition at line 9823 of file item.cpp.

9824{
9825 if( !type->seed ) {
9826 return std::string{};
9827 }
9828 return type->seed->plant_name.translated();
9829}

References itype::seed, and type.

Referenced by map::rotten_item_spawn().

◆ get_property_int64_t()

int64_t item::get_property_int64_t ( const std::string &  prop,
int64_t  def = 0 
) const

Definition at line 5395 of file item.cpp.

5396{
5397 const auto it = type->properties.find( prop );
5398 if( it != type->properties.end() ) {
5399 char *e = nullptr;
5400 int64_t r = std::strtoll( it->second.c_str(), &e, 10 );
5401 if( !it->second.empty() && *e == '\0' ) {
5402 return r;
5403 }
5404 debugmsg( "invalid property '%s' for item '%s'", prop.c_str(), tname() );
5405 }
5406 return def;
5407}
std::map< std::string, std::string > properties
Definition: itype.h:886

References debugmsg, itype::properties, tname(), and type.

Referenced by ranged::throw_item().

◆ get_property_string()

std::string item::get_property_string ( const std::string &  prop,
const std::string &  def = "" 
) const

Get typed property for item.

Return same type as the passed default value, or string where no default provided

Definition at line 5389 of file item.cpp.

5390{
5391 const auto it = type->properties.find( prop );
5392 return it != type->properties.end() ? it->second : def;
5393}

References itype::properties, and type.

Referenced by iuse::capture_monster_act().

◆ get_qualities()

std::map< quality_id, int > item::get_qualities ( ) const

Definition at line 5456 of file item.cpp.

5457{
5458 std::map<quality_id, int> qualities;
5459 for( const auto &quality : type->qualities ) {
5460 qualities[quality.first] = get_quality( quality.first );
5461 }
5462 return qualities;
5463}
int get_quality(const quality_id &id) const
Definition: item.cpp:5409
std::map< quality_id, int > qualities
Definition: itype.h:885

References get_quality(), itype::qualities, and type.

Referenced by inventory::update_quality_cache().

◆ get_quality()

int item::get_quality ( const quality_id id) const

EXCEPTION: Items with quality BOIL only count as such if they are empty, excluding items of their ammo type if they are tools.

Definition at line 5409 of file item.cpp.

5410{
5411 int return_quality = INT_MIN;
5412
5413 /**
5414 * EXCEPTION: Items with quality BOIL only count as such if they are empty,
5415 * excluding items of their ammo type if they are tools.
5416 */
5417 auto block_boil_filter = [this]( const item & itm ) {
5418 // We want to skip (do not block) only those : correct ammo, correct magazine, correct toolmod.Everything else should block.
5419 if( &itm == this ) {
5420 // Do not block if checking itself - we are checking only item contents not item itself.
5421 return false;
5422 } else if( itm.is_ammo() ) {
5423 return ammo_types().count( itm.ammo_type() ) == 0;
5424 } else if( itm.is_magazine() ) {
5425 // we want to return "fine for boiling" if any of the ammo types match and "blocks boiling" if none match.
5426 for( const ammotype &at : ammo_types() ) {
5427 for( const ammotype &mag_at : itm.ammo_types() ) {
5428 if( at == mag_at ) {
5429 return false;
5430 }
5431 }
5432 }
5433 return true;
5434 } else if( itm.is_toolmod() ) {
5435 return false;
5436 }
5437 return true;
5438 };
5439 // if it's has boil quality and it's empty, it's good to boil. If it's not empty and it's not a tool (it's probably a container), it's not good to boil. If it's a tool, it gets an extra chance: if it's only contents are mods or batteries, it's still good.
5440 // Also we are using inverted filter, since we don't care about items that the filter likes, we only care if it find something it doesn't like.
5441 if( id == quality_id( "BOIL" ) && !contents.empty() &&
5442 ( !is_tool() || has_item_with( block_boil_filter ) ) ) {
5443 return INT_MIN;
5444 }
5445
5446 for( const std::pair<const quality_id, int> &quality : type->qualities ) {
5447 if( quality.first == id ) {
5448 return_quality = quality.second;
5449 }
5450 }
5451 return_quality = std::max( return_quality, contents.best_quality( id ) );
5452
5453 return return_quality;
5454}
int best_quality(const quality_id &id) const
string_id< quality > quality_id
Definition: type_id.h:184

References ammo_types(), item_contents::best_quality(), contents, item_contents::empty(), visitable< item >::has_item_with(), is_tool(), itype::qualities, and type.

Referenced by iuse::clear_rubble(), iuse::crowbar(), dig_pit_moves_and_byproducts(), get_qualities(), bionic::get_quality(), has_quality_internal(), Character::item_with_best_of_quality(), activity_handlers::lockpicking_finish(), max_quality_internal(), and pick_lock_actor::use().

◆ get_random_material()

const material_type & item::get_random_material ( ) const

Get a material reference to a random material that this item is made of.

This might return the null-material, you may check this with material_type::ident. Note that this may also return a different material each time it's invoked (if the item is made from several materials).

Definition at line 7172 of file item.cpp.

7173{
7174 return random_entry( made_of(), material_id::NULL_ID() ).obj();
7175}
V random_entry(const C &container, D default_value)
Returns a random entry in the container.
Definition: rng.h:88

References made_of(), string_id< material_type >::NULL_ID(), and random_entry().

Referenced by Character::armor_absorb().

◆ get_relative_health()

float item::get_relative_health ( ) const

Relative item health.

Returns 1 for undamaged ||items, values in the range (0, 1) for damaged items and values above 1 for reinforced ++items.

Definition at line 6247 of file item.cpp.

6248{
6249 return ( max_damage() + 1.0f - damage() ) / ( max_damage() + 1.0f );
6250}

References damage(), and max_damage().

Referenced by get_base_env_resist(), and get_env_resist().

◆ get_relative_rot()

double item::get_relative_rot ( ) const

Get rot value relative to shelf life (or 0 if item does not spoil)

Definition at line 5557 of file item.cpp.

5558{
5559 if( goes_bad() ) {
5560 return rot / get_shelf_life();
5561 }
5562 return 0;
5563}
Definition: rot.cpp:12

References get_shelf_life(), and goes_bad().

Referenced by calc_rot(), Character::consume_effects(), fill_with(), Character::fun_for(), comestible_inventory_preset::get_freshness(), get_freshness_description(), get_most_rotten_component(), comestible_inventory_preset::get_time_left(), has_rotten_away(), item(), and rate_food().

◆ get_relic_recharge_scheme()

const std::vector< relic_recharge > & item::get_relic_recharge_scheme ( ) const

Definition at line 7051 of file item.cpp.

7052{
7053 return relic_data->get_recharge_scheme();
7054}

References relic_data.

Referenced by relic_funcs::process_recharge().

◆ get_reload_time()

int item::get_reload_time ( ) const

Returns the reload time of the gun.

Returns 0 if not a gun.

Definition at line 6554 of file item.cpp.

6555{
6556 if( !is_gun() && !is_magazine() ) {
6557 return 0;
6558 }
6559
6560 int reload_time = is_gun() ? type->gun->reload_time : type->magazine->reload_time;
6561 for( const item *mod : gunmods() ) {
6562 reload_time = static_cast<int>( reload_time * ( 100 + mod->type->gunmod->reload_modifier ) / 100 );
6563 }
6564
6565 return reload_time;
6566}

References itype::gun, gunmods(), is_gun(), is_magazine(), itype::magazine, and type.

Referenced by ideal_ranged_dps(), Character::item_reload_cost(), and item_reload_option::moves().

◆ get_remaining_capacity_for_liquid() [1/2]

int item::get_remaining_capacity_for_liquid ( const item liquid,
bool  allow_bucket = false,
std::string *  err = nullptr 
) const

How much more of this liquid (in charges) can be put in this container.

If this is not a container (or not suitable for the liquid), it returns 0. Note that mixing different types of liquid is not possible. Also note that this works for guns and tools that accept liquid ammo.

Parameters
liquidLiquid to check capacity for
allow_bucketAllow filling non-sealable containers
errMessage to print if no more material will fit

Definition at line 8447 of file item.cpp.

8449{
8450 const auto error = [ &err ]( const std::string & message ) {
8451 if( err != nullptr ) {
8452 *err = message;
8453 }
8454 return 0;
8455 };
8456
8457 int remaining_capacity = 0;
8458
8459 // TODO: (sm) is_reloadable_with and this function call each other and can recurse for
8460 // watertight containers.
8461 if( !is_container() && is_reloadable_with( liquid.typeId() ) ) {
8462 if( ammo_remaining() != 0 && ammo_current() != liquid.typeId() ) {
8463 return error( string_format( _( "You can't mix loads in your %s." ), tname() ) );
8464 }
8465 remaining_capacity = ammo_capacity() - ammo_remaining();
8466 } else if( is_container() ) {
8467 if( !type->container->watertight ) {
8468 return error( string_format( _( "That %s isn't water-tight." ), tname() ) );
8469 } else if( !type->container->seals && ( !allow_bucket || !is_bucket() ) ) {
8470 return error( string_format( is_bucket() ?
8471 _( "That %s must be on the ground or held to hold contents!" )
8472 : _( "You can't seal that %s!" ), tname() ) );
8473 } else if( !contents.empty() && contents.front().typeId() != liquid.typeId() ) {
8474 return error( string_format( _( "You can't mix loads in your %s." ), tname() ) );
8475 }
8476 remaining_capacity = liquid.charges_per_volume( get_container_capacity() );
8477 if( !contents.empty() ) {
8478 remaining_capacity -= contents.front().charges;
8479 }
8480 } else {
8481 return error( string_format( _( "That %1$s won't hold %2$s." ), tname(),
8482 liquid.tname() ) );
8483 }
8484
8485 if( remaining_capacity <= 0 ) {
8486 return error( string_format( _( "Your %1$s can't hold any more %2$s." ), tname(),
8487 liquid.tname() ) );
8488 }
8489
8490 return remaining_capacity;
8491}
std::string message
Definition: mapgen.cpp:420

References _, ammo_capacity(), ammo_current(), ammo_remaining(), charges, charges_per_volume(), itype::container, contents, item_contents::empty(), detail::digits::error, item_contents::front(), get_container_capacity(), is_bucket(), is_container(), is_reloadable_with(), mapgen_defer::message, string_format(), tname(), type, and typeId().

Referenced by add_rain_to_container(), fill_with(), get_remaining_capacity_for_liquid(), is_container_full(), maple_tree_sap_container(), advanced_inventory::move_content(), Character::pour_into(), item_reload_option::qty(), and reload().

◆ get_remaining_capacity_for_liquid() [2/2]

int item::get_remaining_capacity_for_liquid ( const item liquid,
const Character p,
std::string *  err = nullptr 
) const

Definition at line 8493 of file item.cpp.

8495{
8496 const bool allow_bucket = p.is_wielding( *this ) || !p.has_item( *this );
8497 int res = get_remaining_capacity_for_liquid( liquid, allow_bucket, err );
8498
8499 if( res > 0 && !type->rigid && p.inv.has_item( *this ) ) {
8500 const units::volume volume_to_expand = std::max( p.volume_capacity() - p.volume_carried(),
8501 0_ml );
8502
8503 res = std::min( liquid.charges_per_volume( volume_to_expand ), res );
8504
8505 if( res == 0 && err != nullptr ) {
8506 *err = string_format( _( "That %s doesn't have room to expand." ), tname() );
8507 }
8508 }
8509
8510 return res;
8511}
units::volume volume_capacity() const
Definition: character.cpp:2671
bool is_wielding(const item &target) const
Definition: character.cpp:3230
units::volume volume_carried() const
Definition: character.cpp:2543

References _, charges_per_volume(), get_remaining_capacity_for_liquid(), visitable< T >::has_item(), Character::inv, Character::is_wielding(), itype::rigid, string_format(), tname(), type, Character::volume_capacity(), and Character::volume_carried().

◆ get_remaining_chapters()

int item::get_remaining_chapters ( const Character ch) const

Get the number of unread chapters.

If the item is no book or has no chapters, it returns 0. This is a per-character setting, different characters may have different number of unread chapters.

Definition at line 7123 of file item.cpp.

7124{
7125 const std::string var = string_format( "remaining-chapters-%d", ch.getID().get_value() );
7126 return get_var( var, get_chapters() );
7127}

References get_chapters(), character_id::get_value(), get_var(), Character::getID(), and string_format().

Referenced by book_info(), display_name(), character_funcs::get_book_fun_for(), and mark_chapter_as_read().

◆ get_rot()

time_duration item::get_rot ( ) const
inline

Definition at line 860 of file item.h.

860 {
861 return rot;
862 }

Referenced by butchery_drops_harvest(), and has_rotten_away().

◆ get_safe_reference()

safe_reference< item > item::get_safe_reference ( )

Return a pointer-like type that's automatically invalidated if this item is destroyed or assigned-to.

Definition at line 450 of file item.cpp.

451{
452 return anchor.reference_to( this );
453}
safe_reference_anchor anchor
Definition: item.h:2179
safe_reference< T > reference_to(T *object)

References anchor, and safe_reference_anchor::reference_to().

Referenced by active_item_cache::add(), and explosion_handler::ExplosionProcess::move_entity().

◆ get_shelf_life()

time_duration item::get_shelf_life ( ) const

Get the shelf life of the item.

Definition at line 5545 of file item.cpp.

5546{
5547 if( goes_bad() ) {
5548 if( is_food() ) {
5549 return get_comestible()->spoils;
5550 } else if( is_corpse() ) {
5551 return 24_hours;
5552 }
5553 }
5554 return 0_turns;
5555}

References get_comestible(), goes_bad(), is_corpse(), and is_food().

Referenced by basic_info(), calc_rot(), food_info(), get_freshness_description(), get_relative_rot(), process_corpse(), set_relative_rot(), spoilage_sort_order(), and stacks_with().

◆ get_side()

side item::get_side ( ) const

Returns side item currently worn on.

Returns BOTH if item is not sided or no side currently set

Definition at line 812 of file item.cpp.

813{
814 // MSVC complains if directly cast double to enum
815 return static_cast<side>( static_cast<int>( get_var( "lateral",
816 static_cast<int>( side::BOTH ) ) ) );
817}
side
Definition: bodypart.h:68

References BOTH, and get_var().

Referenced by display_name(), get_covered_body_parts(), on_wear(), and swap_side().

◆ get_sizing()

item::sizing item::get_sizing ( const Character p,
bool  wearable 
) const

Definition at line 1181 of file item.cpp.

1182{
1183 if( wearable ) {
1184 const bool small = p.get_size() == MS_TINY;
1185 const bool big = p.get_size() == MS_HUGE;
1186
1187 // due to the iterative nature of these features, something can fit and be undersized/oversized
1188 // but that is fine because we have separate logic to adjust encumberance per each. One day we
1189 // may want to have fit be a flag that only applies if a piece of clothing is sized for you as there
1190 // is a bit of cognitive dissonance when something 'fits' and is 'oversized' and the same time
1191 const bool undersize = has_flag( flag_UNDERSIZE );
1192 const bool oversize = has_flag( flag_OVERSIZE );
1193
1194 if( undersize ) {
1195 if( small ) {
1197 } else if( big ) {
1199 } else {
1201 }
1202 } else if( oversize ) {
1203 if( big ) {
1205 } else if( small ) {
1207 } else {
1209 }
1210 } else {
1211 if( big ) {
1213 } else if( small ) {
1215 } else {
1217 }
1218 }
1219 }
1220 return sizing::not_wearable;
1221
1222}
m_size get_size() const override
Get size class of character.
Definition: character.cpp:576
@ MS_TINY
Definition: creature.h:58
@ MS_HUGE
Definition: creature.h:62
static const std::string flag_UNDERSIZE("UNDERSIZE")
static const std::string flag_OVERSIZE("OVERSIZE")

References big_sized_big_char, big_sized_human_char, big_sized_small_char, flag_OVERSIZE(), flag_UNDERSIZE(), Character::get_size(), has_flag(), human_sized_big_char, human_sized_human_char, human_sized_small_char, MS_HUGE, MS_TINY, not_wearable, small_sized_big_char, small_sized_human_char, and small_sized_small_char.

Referenced by armor_fit_info(), armor_info(), get_encumber_when_containing(), and tname().

◆ get_storage()

units::volume item::get_storage ( ) const

Returns the storage amount (islot_armor::storage) that this item provides when worn.

For non-armor it returns 0. The storage amount increases the volume capacity of the character that wears the item.

Definition at line 5758 of file item.cpp.

5759{
5760 const islot_armor *t = find_armor_data();
5761 if( t == nullptr ) {
5762 return is_pet_armor() ? type->pet_armor->storage : 0_ml;
5763 }
5764 units::volume storage = t->storage;
5766 storage += std::lround( mod ) * units::legacy_volume_factor;
5767
5768 return storage;
5769}
@ clothing_mod_type_storage
Definition: clothing_mod.h:24

References clothing_mod_type_storage, find_armor_data(), get_clothing_mod_val(), is_pet_armor(), units::legacy_volume_factor, itype::pet_armor, islot_armor::storage, and type.

Referenced by animal_armor_info(), armor_info(), armor_inventory_preset::armor_inventory_preset(), anonymous_namespace{armor_layers.cpp}::clothing_properties(), get_encumber(), get_total_capacity(), monexamine::give_items_to(), pickup::obtain_and_tokenize_items(), om_carry_weight_to_trips(), tutorial_game::post_action(), pickup::reorder_for_dropping(), Character::takeoff(), and sew_advanced_actor::use().

◆ get_techniques()

std::set< matec_id > item::get_techniques ( ) const

Returns all the martial art techniques that this items supports.

Definition at line 5501 of file item.cpp.

5502{
5503 std::set<matec_id> result = type->techniques;
5504 result.insert( techniques.begin(), techniques.end() );
5505 return result;
5506}

References techniques, itype::techniques, and type.

Referenced by character_martial_arts::get_all_techniques().

◆ get_thickness()

int item::get_thickness ( ) const

Returns the islot_armor::thickness value, or 0 for non-armor.

Thickness is are relative value that affects the items resistance against bash / cutting / bullet damage.

Definition at line 5935 of file item.cpp.

5936{
5937 const islot_armor *t = find_armor_data();
5938 if( t == nullptr ) {
5939 return is_pet_armor() ? type->pet_armor->thickness : 0;
5940 }
5941 return t->thickness;
5942}
int thickness
TODO: document me.
Definition: itype.h:260

References find_armor_data(), is_pet_armor(), itype::pet_armor, islot_armor::thickness, and type.

Referenced by bash_resist(), bullet_resist(), cut_resist(), clothing_mod::get_mod_val(), and tutorial_game::post_action().

◆ get_total_capacity()

units::volume item::get_total_capacity ( ) const

It returns the maximum volume of any contents, including liquids, ammo, magazines, weapons, etc.

Definition at line 8426 of file item.cpp.

8427{
8429
8430 // Consider various iuse_actors which add containing capability
8431 // Treating these two as special cases for now; if more appear in the
8432 // future then this probably warrants a new method on use_function to
8433 // access this information generically.
8434 if( is_bandolier() ) {
8435 result += dynamic_cast<const bandolier_actor *>
8436 ( type->get_use( "bandolier" )->get_actor_ptr() )->max_stored_volume();
8437 }
8438
8439 if( is_holster() ) {
8440 result += dynamic_cast<const holster_actor *>
8441 ( type->get_use( "holster" )->get_actor_ptr() )->max_stored_volume();
8442 }
8443
8444 return result;
8445}
bool is_holster() const
Definition: item.cpp:6603

References use_function::get_actor_ptr(), get_container_capacity(), get_storage(), itype::get_use(), is_bandolier(), is_holster(), and type.

Referenced by armor_info(), and get_encumber_when_containing().

◆ get_uncraft_components()

std::vector< item_comp > item::get_uncraft_components ( ) const

Returns a list of components used to craft this item or the default components if it wasn't player-crafted.

Definition at line 10087 of file item.cpp.

10088{
10089 std::vector<item_comp> ret;
10090 if( components.empty() ) {
10091 //If item wasn't crafted with specific components use default recipe
10092 std::vector<std::vector<item_comp>> recipe = recipe_dictionary::get_uncraft(
10094 for( std::vector<item_comp> &component : recipe ) {
10095 ret.push_back( component.front() );
10096 }
10097 } else {
10098 //Make a new vector of components from the registered components
10099 for( const item &component : components ) {
10100 auto iter = std::find_if( ret.begin(), ret.end(), [component]( item_comp & obj ) {
10101 return obj.type == component.typeId();
10102 } );
10103
10104 if( iter != ret.end() ) {
10105 iter->count += component.count();
10106 } else {
10107 ret.push_back( item_comp( component.typeId(), component.count() ) );
10108 }
10109 }
10110 }
10111 return ret;
10112}

References components, component::count, recipe::disassembly_requirements(), requirement_data::get_components(), recipe_dictionary::get_uncraft(), cata::hash64_detail::ret, and typeId().

Referenced by disassemble_inventory_preset::disassemble_inventory_preset(), and stacks_with().

◆ get_usable_item()

item * item::get_usable_item ( const std::string &  use_name)

Checks this item and its contents (recursively) for types that have use_function with type use_name.

Returns the first item that does have such type or nullptr if none found.

Definition at line 7991 of file item.cpp.

7992{
7993 item *ret = nullptr;
7995 [&ret, &use_name]( item * it ) {
7996 if( it == nullptr ) {
7997 return VisitResponse::SKIP;
7998 }
7999 if( it->get_use_internal( use_name ) ) {
8000 ret = it;
8001 return VisitResponse::ABORT;
8002 }
8003 return VisitResponse::NEXT;
8004 } );
8005
8006 return ret;
8007}
const use_function * get_use_internal(const std::string &use_name) const
Definition: item.cpp:7983

References get_use_internal(), NEXT, cata::hash64_detail::ret, SKIP, and visitable< item >::visit_items().

Referenced by game::butcher(), activity_handlers::firstaid_finish(), Character::invoke_item(), activity_handlers::longsalvage_finish(), item_action_generator::map_actions_to_items(), activity_handlers::repair_item_finish(), and activity_handlers::start_fire_finish().

◆ get_use()

const use_function * item::get_use ( const std::string &  use_name) const

Returns the pointer to use_function with name use_name assigned to the type of this item or any of its contents.

Checks contents recursively. Returns nullptr if not found.

Definition at line 7965 of file item.cpp.

7966{
7967 const use_function *fun = nullptr;
7969 [&fun, &use_name]( const item * it ) {
7970 if( it == nullptr ) {
7971 return VisitResponse::SKIP;
7972 }
7973 fun = it->get_use_internal( use_name );
7974 if( fun != nullptr ) {
7975 return VisitResponse::ABORT;
7976 }
7977 return VisitResponse::NEXT;
7978 } );
7979
7980 return fun;
7981}

References ABORT, get_use_internal(), NEXT, SKIP, and visitable< item >::visit_items().

Referenced by active_item_cache::add(), game::butcher(), color_in_inventory(), activity_handlers::firstaid_finish(), iuse_transform::info(), activity_handlers::longsalvage_finish(), item_action_generator::map_actions_to_items(), on_takeoff(), on_wear(), process_tool(), read(), active_item_cache::remove(), activity_handlers::repair_item_finish(), sleep(), activity_handlers::start_fire_finish(), avatar::wield(), avatar_action::wield(), and npc::wield_better_weapon().

◆ get_use_internal()

const use_function * item::get_use_internal ( const std::string &  use_name) const
private

Definition at line 7983 of file item.cpp.

7984{
7985 if( type != nullptr ) {
7986 return type->get_use( use_name );
7987 }
7988 return nullptr;
7989}

References itype::get_use(), and type.

Referenced by get_usable_item(), and get_use().

◆ get_var() [1/4]

std::string item::get_var ( const std::string &  name) const

Get the variable, if it does not exists, returns an empty string.

Definition at line 1074 of file item.cpp.

1075{
1076 return get_var( name, "" );
1077}

References get_var(), and om_direction::name().

◆ get_var() [2/4]

std::string item::get_var ( const std::string &  name,
const std::string &  default_value 
) const

Definition at line 1065 of file item.cpp.

1066{
1067 const auto it = item_vars.find( name );
1068 if( it == item_vars.end() ) {
1069 return default_value;
1070 }
1071 return it->second;
1072}

References item_vars, and om_direction::name().

◆ get_var() [3/4]

tripoint item::get_var ( const std::string &  name,
const tripoint default_value 
) const

Definition at line 1048 of file item.cpp.

1049{
1050 const auto it = item_vars.find( name );
1051 if( it == item_vars.end() ) {
1052 return default_value;
1053 }
1054 std::vector<std::string> values = string_split( it->second, ',' );
1055 return tripoint( atoi( values[0].c_str() ),
1056 atoi( values[1].c_str() ),
1057 atoi( values[2].c_str() ) );
1058}
std::vector< std::string > string_split(const std::string &text_in, char delim_in)
Split string by delimiter.

References item_vars, om_direction::name(), and string_split().

◆ get_var() [4/4]

◆ get_warmth()

int item::get_warmth ( ) const

Returns the warmth value that this item has when worn.

See player class for temperature related code, or player::warmth. Returned values should be positive. A value of 0 indicates no warmth from this item at all (this is also the default for non-armor).

Definition at line 5944 of file item.cpp.

5945{
5946 const islot_armor *t = find_armor_data();
5947 if( t == nullptr ) {
5948 return 0;
5949 }
5950 int result = t->warmth;
5951
5953
5954 return result;
5955}
@ clothing_mod_type_warmth
Definition: clothing_mod.h:23
int warmth
How much warmth this item provides.
Definition: itype.h:272

References clothing_mod_type_warmth, find_armor_data(), get_clothing_mod_val(), and islot_armor::warmth.

Referenced by armor_info(), armor_inventory_preset::armor_inventory_preset(), behavior::character_oracle_t::can_wear_warmer_clothes(), anonymous_namespace{armor_layers.cpp}::clothing_properties(), sew_advanced_actor::use(), and Character::warmth().

◆ get_weight_capacity_bonus()

units::mass item::get_weight_capacity_bonus ( ) const

Returns the weight capacity bonus (islot_armor::weight_capacity_modifier) that this item provides when worn.

For non-armor it returns 0. The bonus is added to the total weight capacity of the character that wears the item.

Definition at line 5780 of file item.cpp.

5781{
5782 const islot_armor *t = find_armor_data();
5783 if( t == nullptr ) {
5784 return 0_gram;
5785 }
5786 return t->weight_capacity_bonus;
5787}
units::mass weight_capacity_bonus
Bonus to weight capacity.
Definition: itype.h:284

References find_armor_data(), and islot_armor::weight_capacity_bonus.

Referenced by armor_info().

◆ get_weight_capacity_modifier()

float item::get_weight_capacity_modifier ( ) const

Returns the weight capacity modifier (islot_armor::weight_capacity_modifier) that this item provides when worn.

For non-armor it returns 1. The modifier is multiplied with the weight capacity of the character that wears the item.

Definition at line 5771 of file item.cpp.

5772{
5773 const islot_armor *t = find_armor_data();
5774 if( t == nullptr ) {
5775 return 1;
5776 }
5777 return t->weight_capacity_modifier;
5778}
float weight_capacity_modifier
Factor modifiying weight capacity.
Definition: itype.h:280

References find_armor_data(), and islot_armor::weight_capacity_modifier.

Referenced by armor_info().

◆ getlight()

bool item::getlight ( float &  luminance,
units::angle width,
units::angle direction 
) const

Directional light emission of the item.

Parameters
luminanceThe amount of light (see lightmap.cpp)
widthIf greater 0, the light is emitted in an arc, this is the angle of it.
directionThe direction of the light arc. In degrees.

Definition at line 8380 of file item.cpp.

8381{
8382 luminance = 0;
8383 width = 0_degrees;
8384 direction = 0_degrees;
8385 if( light.luminance > 0 ) {
8386 luminance = static_cast<float>( light.luminance );
8387 if( light.width > 0 ) { // width > 0 is a light arc
8388 width = units::from_degrees( light.width );
8390 }
8391 return true;
8392 } else {
8393 const int lumint = getlight_emit();
8394 if( lumint > 0 ) {
8395 luminance = static_cast<float>( lumint );
8396 return true;
8397 }
8398 }
8399 return false;
8400}
light_emission light
Definition: item.h:2243
int getlight_emit() const
How much light (see lightmap.cpp) the item emits (it's assumed to be circular).
Definition: item.cpp:8402
direction
Definition: line.h:39
constexpr quantity< double, angle_in_radians_tag > from_degrees(const value_type v)
Definition: units_angle.h:31
unsigned short luminance
Definition: item.h:89
short direction
Definition: item.h:91
short width
Definition: item.h:90

References light_emission::direction, units::from_degrees(), getlight_emit(), light, light_emission::luminance, and light_emission::width.

◆ getlight_emit()

int item::getlight_emit ( ) const

How much light (see lightmap.cpp) the item emits (it's assumed to be circular).

Definition at line 8402 of file item.cpp.

8403{
8404 float lumint = type->light_emission;
8405
8406 if( lumint == 0 ) {
8407 return 0;
8408 }
8409 if( has_flag( flag_CHARGEDIM ) && is_tool() && !has_flag( flag_USE_UPS ) ) {
8410 // Falloff starts at 1/5 total charge and scales linearly from there to 0.
8411 if( ammo_capacity() && ammo_remaining() < ( ammo_capacity() / 5 ) ) {
8412 lumint *= ammo_remaining() * 5.0 / ammo_capacity();
8413 }
8414 }
8415 return lumint;
8416}
static const std::string flag_CHARGEDIM("CHARGEDIM")
unsigned light_emission
Definition: itype.h:971

References ammo_capacity(), ammo_remaining(), flag_CHARGEDIM(), flag_USE_UPS(), has_flag(), is_tool(), itype::light_emission, and type.

Referenced by Character::active_light(), and getlight().

◆ goes_bad()

bool item::goes_bad ( ) const

whether an item is perishable (can rot)

Definition at line 5524 of file item.cpp.

5525{
5528 }
5529 if( has_flag( flag_PROCESSING ) ) {
5530 return false;
5531 }
5532 if( is_corpse() ) {
5533 // Corpses rot only if they are made of rotting materials
5535 }
5536 return is_food() && get_comestible()->spoils != 0_turns;
5537}
bool made_of_any(const std::set< material_id > &mat_idents) const
Check we are made of at least one of a set (e.g.
Definition: item.cpp:6461
static const std::string flag_PROCESSING("PROCESSING")
bool goes_bad_cache_fetch()
Definition: item.cpp:338
bool goes_bad_cache_is_for(const item *i)
Definition: item.cpp:352
std::set< material_id > get_rotting()
Definition: material.cpp:327

References flag_PROCESSING(), get_comestible(), materials::get_rotting(), item_internal::goes_bad_cache_fetch(), item_internal::goes_bad_cache_is_for(), has_flag(), is_corpse(), is_food(), and made_of_any().

Referenced by actualize_rot(), basic_info(), crafting::can_disassemble(), complete_craft(), food_info(), get_most_rotten_component(), get_relative_rot(), get_shelf_life(), goes_bad_after_opening(), item_internal::goes_bad_cache_set(), item(), set_relative_rot(), spoilage_sort_order(), stacks_with(), and tname().

◆ goes_bad_after_opening()

bool item::goes_bad_after_opening ( ) const

whether an item is perishable (can rot), even if it is currently in a preserving container

Definition at line 5539 of file item.cpp.

5540{
5541 return goes_bad() || ( type->container && type->container->preserves &&
5542 !contents.empty() && contents.front().goes_bad() );
5543}

References itype::container, contents, item_contents::empty(), item_contents::front(), goes_bad(), and type.

◆ gun_all_modes()

std::map< gun_mode_id, gun_mode > item::gun_all_modes ( ) const

Get all possible modes for this gun inclusive of any attached gunmods.

Definition at line 7856 of file item.cpp.

7857{
7858 std::map<gun_mode_id, gun_mode> res;
7859
7860 if( !is_gun() || is_gunmod() ) {
7861 return res;
7862 }
7863
7864 std::vector<const item *> opts = gunmods();
7865 opts.push_back( this );
7866
7867 for( const item *e : opts ) {
7868
7869 // handle base item plus any auxiliary gunmods
7870 if( e->is_gun() ) {
7871 for( const std::pair<const gun_mode_id, gun_modifier_data> &m : e->type->gun->modes ) {
7872 // prefix attached gunmods, e.g. M203_DEFAULT to avoid index key collisions
7873 std::string prefix = e->is_gunmod() ? ( std::string( e->typeId() ) += "_" ) : "";
7874 std::transform( prefix.begin(), prefix.end(), prefix.begin(),
7875 static_cast<int( * )( int )>( toupper ) );
7876
7877 const int qty = m.second.qty();
7878
7879 res.emplace( gun_mode_id( prefix + m.first.str() ), gun_mode( m.second.name(),
7880 const_cast<item *>( e ),
7881 qty, m.second.flags() ) );
7882 }
7883
7884 // non-auxiliary gunmods may provide additional modes for the base item
7885 } else if( e->is_gunmod() ) {
7886 for( const std::pair<const gun_mode_id, gun_modifier_data> &m : e->type->gunmod->mode_modifier ) {
7887 //checks for melee gunmod, points to gunmod
7888 if( m.first == gun_mode_REACH ) {
7889 res.emplace( m.first, gun_mode { m.second.name(), const_cast<item *>( e ),
7890 m.second.qty(), m.second.flags() } );
7891 //otherwise points to the parent gun, not the gunmod
7892 } else {
7893 res.emplace( m.first, gun_mode { m.second.name(), const_cast<item *>( this ),
7894 m.second.qty(), m.second.flags() } );
7895 }
7896 }
7897 }
7898 }
7899
7900 return res;
7901}
static const gun_mode_id gun_mode_REACH("REACH")
string_id< gun_mode > gun_mode_id
Definition: type_id.h:68

References gun_mode_REACH, gunmods(), is_gun(), is_gunmod(), prefix, and iexamine::transform().

Referenced by target_ui::action_switch_mode(), npc_ai::best_mode_for_range(), can_fire_turret(), npc::confident_shoot_range(), gun_cycle_mode(), gun_get_mode(), gun_set_mode(), game::handle_action(), and reach_range().

◆ gun_current_mode()

gun_mode item::gun_current_mode ( ) const

Get the current mode for this gun (or an invalid mode if item is not a gun)

Definition at line 7915 of file item.cpp.

7916{
7917 return gun_get_mode( gun_get_mode_id() );
7918}
gun_mode_id gun_get_mode_id() const
Get id of mode a gun is currently set to, e.g.
Definition: item.cpp:7920
gun_mode gun_get_mode(const gun_mode_id &mode) const
Check if gun supports a specific mode returning an invalid/empty mode if not.
Definition: item.cpp:7903

References gun_get_mode(), and gun_get_mode_id().

Referenced by avatar_action::can_fire_weapon(), aim_activity_actor::do_turn(), target_ui::ensure_ranged_gun_mode(), npc::execute_action(), aim_activity_actor::finish(), fire(), turret_data::fire(), character_funcs::fmt_wielded_weapon(), info(), aim_activity_actor::load_RAS_weapon(), npc::method_of_attack(), target_ui::panel_fire_mode_aim(), target_ui::panel_gun_info(), turret_data::post_fire(), turret_data::prepare_fire(), print_aim(), turret_data::query(), gun_actor::shoot(), target_ui::update_ammo_range_from_gun_mode(), and target_ui::update_status().

◆ gun_cycle_mode()

void item::gun_cycle_mode ( )

Switch to the next available firing mode.

Definition at line 7937 of file item.cpp.

7938{
7939 if( !is_gun() || is_gunmod() ) {
7940 return;
7941 }
7942
7943 const gun_mode_id cur = gun_get_mode_id();
7944 const std::map<gun_mode_id, gun_mode> modes = gun_all_modes();
7945
7946 for( auto iter = modes.begin(); iter != modes.end(); ++iter ) {
7947 if( iter->first == cur ) {
7948 if( std::next( iter ) == modes.end() ) {
7949 break;
7950 }
7951 gun_set_mode( std::next( iter )->first );
7952 return;
7953 }
7954 }
7955 gun_set_mode( modes.begin()->first );
7956
7957 return;
7958}
std::map< gun_mode_id, gun_mode > gun_all_modes() const
Get all possible modes for this gun inclusive of any attached gunmods.
Definition: item.cpp:7856
bool gun_set_mode(const gun_mode_id &mode)
Try to set the mode for a gun, returning false if no such mode is possible.
Definition: item.cpp:7928

References gun_all_modes(), gun_get_mode_id(), gun_set_mode(), is_gun(), and is_gunmod().

Referenced by target_ui::ensure_ranged_gun_mode(), and game::handle_action().

◆ gun_damage()

damage_instance item::gun_damage ( bool  with_ammo = true) const

Summed ranged damage, armor piercing, and multipliers for both, of a gun, including values from mods.

Returns empty instance on non-gun items.

Definition at line 7293 of file item.cpp.

7294{
7295 if( !is_gun() ) {
7296 return damage_instance();
7297 }
7298 damage_instance ret = type->gun->damage;
7299
7300 for( const item *mod : gunmods() ) {
7301 ret.add( mod->type->gunmod->damage );
7302 }
7303
7304 if( with_ammo && ammo_data() ) {
7305 ret.add( ammo_data()->ammo->damage );
7306 }
7307
7308 int item_damage = damage_level( 4 );
7309 if( item_damage > 0 ) {
7310 // TODO: This isn't a good solution for multi-damage guns/ammos
7311 for( damage_unit &du : ret ) {
7312 if( du.amount <= 1.0 ) {
7313 continue;
7314 }
7315 du.amount = std::max<float>( 1.0f, du.amount - item_damage * 2 );
7316 }
7317 }
7318
7319 return ret;
7320}

References ammo_data(), damage_level(), itype::gun, gunmods(), is_gun(), cata::hash64_detail::ret, and type.

Referenced by gun_info(), ideal_ranged_dps(), make_gun_projectile(), and weapon_inventory_preset::weapon_inventory_preset().

◆ gun_dispersion()

int item::gun_dispersion ( bool  with_ammo = true,
bool  with_scaling = true 
) const

Summed dispersion of a gun, including values from mods.

Returns 0 on non-gun items.

Definition at line 7246 of file item.cpp.

7247{
7248 if( !is_gun() ) {
7249 return 0;
7250 }
7251 int dispersion_sum = type->gun->dispersion;
7252 for( const item *mod : gunmods() ) {
7253 dispersion_sum += mod->type->gunmod->dispersion;
7254 }
7255 int dispPerDamage = get_option< int >( "DISPERSION_PER_GUN_DAMAGE" );
7256 dispersion_sum += damage_level( 4 ) * dispPerDamage;
7257 dispersion_sum = std::max( dispersion_sum, 0 );
7258 if( with_ammo && ammo_data() ) {
7259 dispersion_sum += ammo_data()->ammo->dispersion;
7260 }
7261 if( !with_scaling ) {
7262 return dispersion_sum;
7263 }
7264
7265 // Dividing dispersion by 15 temporarily as a gross adjustment,
7266 // will bake that adjustment into individual gun definitions in the future.
7267 // Absolute minimum gun dispersion is 1.
7268 double divider = get_option< float >( "GUN_DISPERSION_DIVIDER" );
7269 dispersion_sum = std::max( static_cast<int>( std::round( dispersion_sum / divider ) ), 1 );
7270
7271 return dispersion_sum;
7272}

References itype::ammo, ammo_data(), damage_level(), itype::gun, gunmods(), is_gun(), and type.

Referenced by gun_info().

◆ gun_get_mode()

gun_mode item::gun_get_mode ( const gun_mode_id mode) const

Check if gun supports a specific mode returning an invalid/empty mode if not.

Definition at line 7903 of file item.cpp.

7904{
7905 if( is_gun() ) {
7906 for( const std::pair<const gun_mode_id, gun_mode> &e : gun_all_modes() ) {
7907 if( e.first == mode ) {
7908 return e.second;
7909 }
7910 }
7911 }
7912 return gun_mode();
7913}

References gun_all_modes(), and is_gun().

Referenced by mattack::frag(), gun_current_mode(), mattack::rifle(), and mattack::tankgun().

◆ gun_get_mode_id()

gun_mode_id item::gun_get_mode_id ( ) const

Get id of mode a gun is currently set to, e.g.

DEFAULT, AUTO, BURST

Definition at line 7920 of file item.cpp.

7921{
7922 if( !is_gun() || is_gunmod() ) {
7923 return gun_mode_id();
7924 }
7925 return gun_mode_id( get_var( GUN_MODE_VAR_NAME, "DEFAULT" ) );
7926}
static const std::string GUN_MODE_VAR_NAME("item::mode")

References get_var(), GUN_MODE_VAR_NAME(), is_gun(), and is_gunmod().

Referenced by target_ui::action_switch_mode(), gun_current_mode(), and gun_cycle_mode().

◆ gun_info()

void item::gun_info ( const item mod,
std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 2021 of file item.cpp.

2023{
2024 const std::string space = " ";
2025 const islot_gun &gun = *mod->type->gun;
2026 const Skill &skill = *mod->gun_skill();
2027 avatar &viewer = get_avatar();
2028
2029 // many statistics are dependent upon loaded ammo
2030 // if item is unloaded (or is RELOAD_AND_SHOOT) shows approximate stats using default ammo
2031 const item *loaded_mod = mod;
2032 item tmp;
2033 if( mod->ammo_required() && !mod->ammo_remaining() ) {
2034 tmp = *mod;
2035 tmp.ammo_set( mod->magazine_current() ? tmp.common_ammo_default() : tmp.ammo_default() );
2036 if( tmp.ammo_data() == nullptr ) {
2038 info.emplace_back( "GUN",
2039 _( "Weapon <bad>can't be loaded in its current state</bad>." ) );
2040 return;
2041 }
2042 loaded_mod = &tmp;
2043 if( parts->test( iteminfo_parts::GUN_DEFAULT_AMMO ) ) {
2045 info.emplace_back( "GUN",
2046 _( "Weapon is <bad>not loaded</bad>, so stats below assume the default ammo: " ),
2047 string_format( "<stat>%s</stat>",
2048 loaded_mod->ammo_data()->nname( 1 ) ) );
2049 }
2050 }
2051
2052 const itype *curammo = loaded_mod->ammo_data();
2053 if( mod->ammo_required() && !curammo ) {
2054 debugmsg( "curammo is nullptr in item::gun_info()" );
2055 return;
2056 }
2057 damage_unit gun_du = gun_damage( false ).damage_units.front();
2058
2060
2061 const damage_unit &ammo_du = curammo != nullptr
2062 ? curammo->ammo->damage.damage_units.front()
2063 : damage_unit( DT_STAB, 0 );
2064
2065 if( parts->test( iteminfo_parts::GUN_DAMAGE ) ) {
2067 info.push_back( iteminfo( "GUN", _( "<bold>Ranged damage</bold>: " ), "", iteminfo::no_newline,
2068 gun_du.amount ) );
2069 }
2070
2071 if( mod->ammo_required() ) {
2072 // ammo_damage, sum_of_damage, and ammo_mult not shown so don't need to translate.
2074 assert( curammo ); // Appease clang-tidy
2075 damage_instance ammo_dam = curammo->ammo->damage;
2076 info.push_back( iteminfo( "GUN", "ammo_damage", "",
2078 iteminfo::show_plus, ammo_du.amount ) );
2079 }
2080
2081 if( parts->test( iteminfo_parts::GUN_DAMAGE_TOTAL ) ) {
2082 // Intentionally not using total_damage() as it applies multipliers
2083 info.push_back( iteminfo( "GUN", "sum_of_damage", _( " = <num>" ),
2085 gun_du.amount + ammo_du.amount ) );
2086 }
2087 }
2088 info.back().bNewLine = true;
2089 avatar &you = get_avatar();
2090 int max_gun_range = loaded_mod->gun_range( &you );
2091 if( max_gun_range > 0 && parts->test( iteminfo_parts::GUN_MAX_RANGE ) ) {
2092 info.emplace_back( "GUN", _( "Maximum range: " ), "<num>", iteminfo::no_flags,
2093 max_gun_range );
2094 }
2095
2096 // TODO: This doesn't cover multiple damage types
2097 if( parts->test( iteminfo_parts::GUN_ARMORPIERCE ) ) {
2098 info.push_back( iteminfo( "GUN", _( "Armor-pierce: " ), "",
2100 }
2101 if( mod->ammo_required() ) {
2102 assert( curammo ); // Appease clang-tidy
2103 int ammo_pierce = get_ranged_pierce( *curammo->ammo );
2104 // ammo_armor_pierce and sum_of_armor_pierce don't need to translate.
2106 info.push_back( iteminfo( "GUN", "ammo_armor_pierce", "",
2108 iteminfo::show_plus, ammo_pierce ) );
2109 }
2111 info.push_back( iteminfo( "GUN", "sum_of_armor_pierce", _( " = <num>" ),
2113 get_ranged_pierce( gun ) + ammo_pierce ) );
2114 }
2115 }
2116 info.back().bNewLine = true;
2117
2118 if( parts->test( iteminfo_parts::GUN_DAMAGEMULT ) ) {
2119 info.push_back( iteminfo( "GUN", _( "Damage multiplier: " ), "",
2121 gun_du.damage_multiplier ) );
2122 }
2123
2124 if( mod->ammo_required() ) {
2126 info.push_back( iteminfo( "GUN", "ammo_mult", "*",
2128 ammo_du.damage_multiplier ) );
2129 }
2130
2132 info.push_back( iteminfo( "GUN", "sum_of_damage", _( " = <num>" ),
2134 gun_du.damage_multiplier * ammo_du.damage_multiplier ) );
2135 }
2136 }
2137 info.back().bNewLine = true;
2138
2139 if( parts->test( iteminfo_parts::GUN_ARMORMULT ) ) {
2140 info.push_back( iteminfo( "GUN", _( "Armor multiplier: " ), "",
2142 gun_du.res_mult ) );
2143 }
2144 if( mod->ammo_required() ) {
2146 info.push_back( iteminfo( "GUN", "ammo_armor_mult", _( "*<num>" ),
2149 ammo_du.res_mult ) );
2150 }
2152 info.push_back( iteminfo( "GUN", "final_armor_mult", _( " = <num>" ),
2154 gun_du.res_mult * ammo_du.res_mult ) );
2155 }
2156 }
2157 info.back().bNewLine = true;
2158
2159 if( parts->test( iteminfo_parts::GUN_DISPERSION ) ) {
2160 info.push_back( iteminfo( "GUN", _( "Dispersion: " ), "",
2162 mod->gun_dispersion( false, false ) ) );
2163 }
2164 if( mod->ammo_required() ) {
2165 int ammo_dispersion = curammo->ammo->dispersion;
2166 // ammo_dispersion and sum_of_dispersion don't need to translate.
2168 info.push_back( iteminfo( "GUN", "ammo_dispersion", "",
2171 ammo_dispersion ) );
2172 }
2174 info.push_back( iteminfo( "GUN", "sum_of_dispersion", _( " = <num>" ),
2176 loaded_mod->gun_dispersion( true, false ) ) );
2177 info.push_back( iteminfo( "GUN", "eff_dispersion", _( " (effective: <num>)" ),
2179 static_cast<int>( ranged::get_weapon_dispersion( you, *this ).max() ) ) );
2180 }
2181 }
2182 info.back().bNewLine = true;
2183
2184 // if effective sight dispersion differs from actual sight dispersion display both
2185 int act_disp = mod->sight_dispersion();
2186 int eff_disp = ranged::effective_dispersion( you, act_disp );
2187 int adj_disp = eff_disp - act_disp;
2188
2190 info.push_back( iteminfo( "GUN", _( "Sight dispersion: " ), "",
2192 act_disp ) );
2193
2194 if( adj_disp ) {
2195 info.push_back( iteminfo( "GUN", "sight_adj_disp", "",
2197 iteminfo::no_name | iteminfo::show_plus, adj_disp ) );
2198 info.push_back( iteminfo( "GUN", "sight_eff_disp", _( " = <num>" ),
2200 eff_disp ) );
2201 }
2202 }
2203
2204 bool bipod = mod->has_flag( flag_BIPOD );
2205
2206 if( loaded_mod->gun_recoil() ) {
2208 info.emplace_back( "GUN", _( "Recoil percentage: " ), "",
2210 std::ceil( 100 * loaded_mod->gun_recoil_multiplier() ) );
2211 }
2212 if( bipod && parts->test( iteminfo_parts::GUN_RECOIL_PERCENTAGE_BIPOD ) ) {
2213 info.emplace_back( "GUN", "bipod_recoil_percentage", _( " (with bipod <num>)" ),
2215 std::ceil( 100 * loaded_mod->gun_recoil_multiplier( true ) ) );
2216 }
2217 info.back().bNewLine = true;
2218
2219 if( parts->test( iteminfo_parts::GUN_RECOIL ) ) {
2220 info.emplace_back( "GUN", _( "Effective recoil: " ), "",
2222 loaded_mod->gun_recoil() );
2223 }
2224 if( bipod && parts->test( iteminfo_parts::GUN_RECOIL_BIPOD ) ) {
2225 info.emplace_back( "GUN", "bipod_recoil", _( " (with bipod <num>)" ),
2227 loaded_mod->gun_recoil( true ) );
2228 }
2229 }
2230 info.back().bNewLine = true;
2231
2232 std::map<gun_mode_id, gun_mode> fire_modes = mod->gun_all_modes();
2233 if( parts->test( iteminfo_parts::GUN_BURST_PENALTY ) ) {
2234 if( std::any_of( fire_modes.begin(), fire_modes.end(),
2235 []( const std::pair<gun_mode_id, gun_mode> &e ) {
2236 return e.second.qty > 1 && !e.second.melee();
2237 } ) ) {
2238 info.emplace_back( "GUN", _( "Burst fire penalty: " ), "",
2240 ranged::burst_penalty( you, *this, loaded_mod->gun_recoil() ) );
2241 if( bipod ) {
2242 info.emplace_back( "GUN", "bipod_burst", _( " (with bipod <num>)" ),
2244 ranged::burst_penalty( you, *this, loaded_mod->gun_recoil( true ) ) );
2245 }
2246 }
2247 info.back().bNewLine = true;
2248 }
2249
2250 if( parts->test( iteminfo_parts::GUN_RELOAD_TIME ) ) {
2251 info.emplace_back( "GUN", _( "Reload time: " ),
2252 has_flag( flag_RELOAD_ONE ) ? _( "<num> moves per round" ) :
2253 _( "<num> moves " ),
2254 iteminfo::lower_is_better, mod->get_reload_time() );
2255 }
2256
2257 if( parts->test( iteminfo_parts::GUN_USEDSKILL ) ) {
2258 info.push_back( iteminfo( "GUN", _( "Skill used: " ),
2259 "<info>" + skill.name() + "</info>" ) );
2260 }
2261
2262 if( mod->magazine_integral() || mod->magazine_current() ) {
2263 if( mod->magazine_current() && parts->test( iteminfo_parts::GUN_MAGAZINE ) ) {
2264 info.emplace_back( "GUN", _( "Magazine: " ),
2265 string_format( "<stat>%s</stat>",
2266 mod->magazine_current()->tname() ) );
2267 }
2268 if( mod->ammo_capacity() && parts->test( iteminfo_parts::GUN_CAPACITY ) ) {
2269 for( const ammotype &at : mod->ammo_types() ) {
2270 const std::string fmt = string_format( vgettext( "<num> round of %s",
2271 "<num> rounds of %s",
2272 mod->ammo_capacity() ), at->name() );
2273 info.emplace_back( "GUN", _( "Capacity: " ), fmt, iteminfo::no_flags,
2274 mod->ammo_capacity() );
2275 }
2276 }
2277 } else if( parts->test( iteminfo_parts::GUN_TYPE ) ) {
2278 info.emplace_back( "GUN", _( "Type: " ), enumerate_as_string( mod->ammo_types().begin(),
2279 mod->ammo_types().end(), []( const ammotype & at ) {
2280 return at->name();
2282 }
2283
2284 if( mod->ammo_data() && parts->test( iteminfo_parts::AMMO_REMAINING ) ) {
2285 info.emplace_back( "AMMO", _( "Ammunition: " ), string_format( "<stat>%s</stat>",
2286 mod->ammo_data()->nname( mod->ammo_remaining() ) ) );
2287 }
2288
2289 if( mod->get_gun_ups_drain() && parts->test( iteminfo_parts::AMMO_UPSCOST ) ) {
2290 info.emplace_back( "AMMO",
2291 string_format( vgettext( "Uses <stat>%i</stat> charge of UPS per shot",
2292 "Uses <stat>%i</stat> charges of UPS per shot",
2293 mod->get_gun_ups_drain() ),
2294 mod->get_gun_ups_drain() ) );
2295 }
2296
2297 if( parts->test( iteminfo_parts::GUN_AIMING_STATS ) ) {
2299 info.emplace_back( "GUN", _( "<bold>Base aim speed</bold>: " ), "<num>", iteminfo::no_flags,
2301 for( const ranged::aim_type &type : ranged::get_aim_types( you, *mod ) ) {
2302 // Nameless aim levels don't get an entry.
2303 if( type.name.empty() ) {
2304 continue;
2305 }
2306 // For item comparison to work correctly each info object needs a
2307 // distinct tag per aim type.
2308 const std::string tag = "GUN_" + type.name;
2309 info.emplace_back( tag, string_format( "<info>%s</info>", type.name ) );
2310 int max_dispersion = ranged::get_weapon_dispersion( you, *loaded_mod ).max();
2311 int range = range_with_even_chance_of_good_hit( max_dispersion + type.threshold );
2312 info.emplace_back( tag, _( "Even chance of good hit at range: " ),
2313 _( "<num>" ), iteminfo::no_flags, range );
2314 int aim_mv = ranged::gun_engagement_moves( you, *mod, type.threshold );
2315 info.emplace_back( tag, _( "Time to reach aim level: " ), _( "<num> moves " ),
2316 iteminfo::lower_is_better, aim_mv );
2317 }
2318 }
2319
2320 if( parts->test( iteminfo_parts::GUN_FIRE_MODES ) ) {
2321 std::vector<std::string> fm;
2322 for( const std::pair<const gun_mode_id, gun_mode> &e : fire_modes ) {
2323 if( e.second.target == this && !e.second.melee() ) {
2324 fm.emplace_back( string_format( "%s (%i)", e.second.tname(), e.second.qty ) );
2325 }
2326 }
2327 if( !fm.empty() ) {
2329 info.emplace_back( "GUN", _( "<bold>Fire modes</bold>: " ) +
2330 enumerate_as_string( fm ) );
2331 }
2332 }
2333
2336 const std::set<itype_id> compat = magazine_compatible();
2337 info.emplace_back( "DESCRIPTION", _( "<bold>Compatible magazines</bold>: " ) +
2338 enumerate_as_string( compat.begin(), compat.end(), []( const itype_id & id ) {
2339 return item::nname( id );
2340 } ) );
2341 }
2342
2343 if( !gun.valid_mod_locations.empty() && parts->test( iteminfo_parts::DESCRIPTION_GUN_MODS ) ) {
2345
2346 std::string mod_str = _( "<bold>Mods</bold>: " );
2347
2348 std::map<gunmod_location, int> mod_locations = get_mod_locations();
2349
2350 int iternum = 0;
2351 for( std::pair<const gunmod_location, int> &elem : mod_locations ) {
2352 if( iternum != 0 ) {
2353 mod_str += "; ";
2354 }
2355 const int free_slots = ( elem ).second - get_free_mod_locations( elem.first );
2356 mod_str += string_format( "<bold>%d/%d</bold> %s", free_slots, elem.second,
2357 elem.first.name() );
2358 bool first_mods = true;
2359 for( const item *gmod : gunmods() ) {
2360 if( gmod->type->gunmod->location == ( elem ).first ) { // if mod for this location
2361 if( first_mods ) {
2362 mod_str += ": ";
2363 first_mods = false;
2364 } else {
2365 mod_str += ", ";
2366 }
2367 mod_str += string_format( "<stat>%s</stat>", gmod->tname() );
2368 }
2369 }
2370 iternum++;
2371 }
2372 mod_str += ".";
2373 info.push_back( iteminfo( "DESCRIPTION", mod_str ) );
2374 }
2375
2376 if( mod->casings_count() && parts->test( iteminfo_parts::DESCRIPTION_GUN_CASINGS ) ) {
2378 std::string tmp = vgettext( "Contains <stat>%i</stat> casing",
2379 "Contains <stat>%i</stat> casings", mod->casings_count() );
2380 info.emplace_back( "DESCRIPTION", string_format( tmp, mod->casings_count() ) );
2381 }
2382}
@ range
Definition: character.h:104
Definition: skill.h:33
double max() const
Definition: dispersion.cpp:20
int gun_recoil(bool bipod=false) const
Get effective recoil considering handling, loaded ammo and effects of attached gunmods.
Definition: item.cpp:7342
itype_id common_ammo_default(bool conversion=true) const
Get default ammo for the first ammotype common to an item and its current magazine or "NULL" if none ...
Definition: item.cpp:7630
int get_free_mod_locations(const gunmod_location &location) const
Number of mods that can still be installed into the given mod location, for non-guns it always return...
Definition: item.cpp:4116
damage_instance gun_damage(bool with_ammo=true) const
Summed ranged damage, armor piercing, and multipliers for both, of a gun, including values from mods.
Definition: item.cpp:7293
int gun_dispersion(bool with_ammo=true, bool with_scaling=true) const
Summed dispersion of a gun, including values from mods.
Definition: item.cpp:7246
double gun_recoil_multiplier(bool bipod=false) const
Get multiplier on recoil considering handling and attached gunmods.
Definition: item.cpp:7322
int gun_range(const player *p) const
The weapons range in map squares.
Definition: item.cpp:7375
bool empty() const
Whether the underlying string is empty, not matter what the context is or whether translation is need...
constexpr double MAX_RECOIL
static const std::string flag_RELOAD_ONE("RELOAD_ONE")
static const std::string flag_BIPOD("BIPOD")
@ GUN_ARMORPIERCE_LOADEDAMMO
@ GUN_RECOIL_PERCENTAGE_BIPOD
int gun_engagement_moves(const Character &who, const item &gun, int target=0, int start=MAX_RECOIL)
How many moves does it take to aim gun to the target accuracy.
Definition: ranged.cpp:584
float str_draw_damage_modifier(const item &it, const Character &p)
Definition: ranged.cpp:1032
int burst_penalty(const Character &p, const item &gun, int gun_recoil)
Definition: ranged.cpp:2163
std::vector< aim_type > get_aim_types(const Character &who, const item &gun)
Definition: ranged.cpp:1651
int effective_dispersion(const Character &who, int dispersion)
Definition: ranged.cpp:3821
dispersion_sources get_weapon_dispersion(const Character &who, const item &obj)
Get weapon's dispersion value modified accoring to character stats.
Definition: ranged.cpp:1918
double aim_per_move(const Character &who, const item &gun, double recoil)
Calculates aim improvement per move spent aiming at a given.
Definition: ranged.cpp:3920
int range_with_even_chance_of_good_hit(int dispersion)
Definition: ranged.cpp:573
float amount
Definition: damage.h:37
float res_mult
Definition: damage.h:39
std::map< gunmod_location, int > valid_mod_locations
Location for gun mods.
Definition: itype.h:521
@ no_name
Do not print the name.
Definition: item.h:148
translation name
unique string identifier for this type
Definition: itype.h:858

References _, ranged::aim_per_move(), itype::ammo, ammo_data(), ammo_default(), AMMO_REMAINING, ammo_set(), AMMO_UPSCOST, damage_unit::amount, ranged::burst_penalty(), common_ammo_default(), curammo, damage_unit::damage_multiplier, damage_instance::damage_units, debugmsg, DESCRIPTION_GUN_CASINGS, DESCRIPTION_GUN_MODS, DT_STAB, ranged::effective_dispersion(), translation::empty(), enumerate_as_string(), flag_BIPOD(), flag_RELOAD_ONE(), ranged::get_aim_types(), get_avatar(), get_free_mod_locations(), get_mod_locations(), get_ranged_pierce(), ranged::get_weapon_dispersion(), GUN_AIMING_STATS, GUN_ALLOWED_MAGAZINES, GUN_ARMORMULT, GUN_ARMORMULT_LOADEDAMMO, GUN_ARMORMULT_TOTAL, GUN_ARMORPIERCE, GUN_ARMORPIERCE_LOADEDAMMO, GUN_ARMORPIERCE_TOTAL, GUN_BURST_PENALTY, GUN_CAPACITY, gun_damage(), GUN_DAMAGE, GUN_DAMAGE_LOADEDAMMO, GUN_DAMAGE_TOTAL, GUN_DAMAGEMULT, GUN_DAMAGEMULT_AMMO, GUN_DAMAGEMULT_TOTAL, GUN_DEFAULT_AMMO, gun_dispersion(), GUN_DISPERSION, GUN_DISPERSION_LOADEDAMMO, GUN_DISPERSION_SIGHT, GUN_DISPERSION_TOTAL, ranged::gun_engagement_moves(), GUN_FIRE_MODES, GUN_MAGAZINE, GUN_MAX_RANGE, gun_range(), gun_recoil(), GUN_RECOIL, GUN_RECOIL_BIPOD, gun_recoil_multiplier(), GUN_RECOIL_PERCENTAGE, GUN_RECOIL_PERCENTAGE_BIPOD, GUN_RELOAD_TIME, GUN_TYPE, GUN_USEDSKILL, gunmods(), has_flag(), info(), insert_separation_line(), iteminfo::is_decimal, iteminfo::lower_is_better, magazine_compatible(), magazine_integral(), dispersion_sources::max(), MAX_RECOIL, itype::name, Skill::name(), itype::nname(), iteminfo::no_flags, iteminfo::no_name, iteminfo::no_newline, none, range, range_with_even_chance_of_good_hit(), damage_unit::res_mult, second, iteminfo::show_plus, sign::space, ranged::str_draw_damage_modifier(), string_format(), iteminfo_query::test(), type, islot_gun::valid_mod_locations, and vgettext().

Referenced by info().

◆ gun_noise()

item::sound_data item::gun_noise ( bool  burst = false) const

Returns the sound of the gun being fired.

Parameters
burstWhether the gun was fired in burst mode (the sound string is usually different).

Definition at line 1813 of file ranged.cpp.

1814{
1815 if( !is_gun() ) {
1816 return { 0, "" };
1817 }
1818
1819 int noise = type->gun->loudness;
1820 for( const auto mod : gunmods() ) {
1821 noise += mod->type->gunmod->loudness;
1822 }
1823 if( ammo_data() ) {
1824 noise += ammo_data()->ammo->loudness;
1825 }
1826
1827 noise = std::max( noise, 0 );
1828
1830 // Grenade launchers
1831 return { 8, _( "Thunk!" ) };
1832
1833 } else if( ammo_current() == itype_12mm || ammo_current() == itype_metal_rail ) {
1834 // Railguns
1835 return { 24, _( "tz-CRACKck!" ) };
1836
1837 } else if( ammo_current() == itype_flammable || ammo_current() == itype_66mm ||
1839 // Rocket launchers and flamethrowers
1840 return { 4, _( "Fwoosh!" ) };
1841 } else if( ammo_current() == itype_arrow ) {
1842 return { noise, _( "whizz!" ) };
1843 } else if( ammo_current() == itype_bolt ) {
1844 return { noise, _( "thonk!" ) };
1845 }
1846
1847 auto fx = ammo_effects();
1848
1849 if( fx.count( ammo_effect_LASER ) || fx.count( ammo_effect_PLASMA ) ) {
1850 if( noise < 20 ) {
1851 return { noise, _( "Fzzt!" ) };
1852 } else if( noise < 40 ) {
1853 return { noise, _( "Pew!" ) };
1854 } else if( noise < 60 ) {
1855 return { noise, _( "Tsewww!" ) };
1856 } else {
1857 return { noise, _( "Kra-kow!" ) };
1858 }
1859
1860 } else if( fx.count( ammo_effect_LIGHTNING ) ) {
1861 if( noise < 20 ) {
1862 return { noise, _( "Bzzt!" ) };
1863 } else if( noise < 40 ) {
1864 return { noise, _( "Bzap!" ) };
1865 } else if( noise < 60 ) {
1866 return { noise, _( "Bzaapp!" ) };
1867 } else {
1868 return { noise, _( "Kra-koom!" ) };
1869 }
1870
1871 } else if( fx.count( ammo_effect_WHIP ) ) {
1872 return { noise, _( "Crack!" ) };
1873
1874 } else if( noise > 0 ) {
1875 if( noise < 10 ) {
1876 return { noise, burst ? _( "Brrrip!" ) : _( "plink!" ) };
1877 } else if( noise < 150 ) {
1878 return { noise, burst ? _( "Brrrap!" ) : _( "bang!" ) };
1879 } else if( noise < 175 ) {
1880 return { noise, burst ? _( "P-p-p-pow!" ) : _( "blam!" ) };
1881 } else {
1882 return { noise, burst ? _( "Kaboom!" ) : _( "kerblam!" ) };
1883 }
1884 }
1885
1886 return { 0, "" }; // silent weapons
1887}
std::set< ammo_effect_str_id > ammo_effects(bool with_ammo=true) const
Get ammo effects for item optionally inclusive of any resulting from the loaded ammo.
Definition: item.cpp:7646
static const ammo_effect_str_id ammo_effect_WHIP("WHIP")
static const ammo_effect_str_id ammo_effect_LIGHTNING("LIGHTNING")
static const itype_id itype_12mm("12mm")
static const itype_id itype_flammable("flammable")
static const itype_id itype_m235("m235")
static const ammo_effect_str_id ammo_effect_LASER("LASER")
static const itype_id itype_40x46mm("40x46mm")
static const itype_id itype_40x53mm("40x53mm")
static const itype_id itype_bolt("bolt")
static const itype_id itype_84x246mm("84x246mm")
static const itype_id itype_metal_rail("metal_rail")
static const ammo_effect_str_id ammo_effect_PLASMA("PLASMA")
static const itype_id itype_66mm("66mm")
static const itype_id itype_arrow("arrow")

References _, itype::ammo, ammo_current(), ammo_data(), ammo_effect_LASER, ammo_effect_LIGHTNING, ammo_effect_PLASMA, ammo_effect_WHIP, ammo_effects(), itype::gun, gunmods(), is_gun(), itype_12mm, itype_40x46mm, itype_40x53mm, itype_66mm, itype_84x246mm, itype_arrow, itype_bolt, itype_flammable, itype_m235, itype_metal_rail, noise, and type.

Referenced by is_silent(), ranged::make_gun_sound_effect(), and npc::pretend_fire().

◆ gun_range() [1/2]

int item::gun_range ( bool  with_ammo = true) const

Summed range value of a gun, including values from mods.

Returns 0 on non-gun items.

Definition at line 7356 of file item.cpp.

7357{
7358 if( !is_gun() ) {
7359 return 0;
7360 }
7361 int ret = type->gun->range;
7362 for( const item *mod : gunmods() ) {
7363 ret += mod->type->gunmod->range;
7364 }
7365 if( with_ammo && ammo_data() ) {
7366 if( ammo_data()->ammo->shape ) {
7367 ret = ammo_data()->ammo->shape->get_range();
7368 } else {
7369 ret += ammo_data()->ammo->range;
7370 }
7371 }
7372 return std::min( std::max( 0, ret ), RANGE_HARD_CAP );
7373}
static constexpr int RANGE_HARD_CAP

References itype::ammo, ammo_data(), itype::gun, gunmods(), is_gun(), RANGE_HARD_CAP, cata::hash64_detail::ret, and type.

◆ gun_range() [2/2]

int item::gun_range ( const player p) const

The weapons range in map squares.

If the item has an active gunmod, it returns the range of that gunmod, the guns range is returned only when the item has no active gunmod. This function applies to guns and auxiliary gunmods. For other items, 0 is returned. It includes the range given by the ammo.

Parameters
pThe player that uses the weapon, their strength might affect this. It's optional and can be null.

Definition at line 7375 of file item.cpp.

7376{
7377 int ret = gun_range( true );
7378 if( p == nullptr ) {
7379 return ret;
7380 }
7381 if( !p->meets_requirements( *this ) ) {
7382 return 0;
7383 }
7384
7385 // Reduce bow range if player has less than minimum strength.
7386 ret *= ranged::str_draw_range_modifier( *this, *p );
7387
7388 return std::max( 0, ret );
7389}
bool meets_requirements(const item &it, const item &context=item()) const
Checks whether the character meets overall requirements to be able to use the item.
Definition: character.cpp:3543
float str_draw_range_modifier(const item &it, const Character &p)
Definition: ranged.cpp:1058

References gun_range(), Character::meets_requirements(), cata::hash64_detail::ret, and ranged::str_draw_range_modifier().

Referenced by gun_info(), gun_range(), game::list_monsters(), make_gun_projectile(), turret_data::range(), and target_ui::update_ammo_range_from_gun_mode().

◆ gun_recoil()

int item::gun_recoil ( bool  bipod = false) const

Get effective recoil considering handling, loaded ammo and effects of attached gunmods.

Parameters
bipodwhether any bipods should be considered
Returns
effective recoil (per shot) or zero if gun uses ammo and none is loaded

Definition at line 7342 of file item.cpp.

7343{
7344 if( !is_gun() || ( ammo_required() && !ammo_remaining() ) ) {
7345 return 0;
7346 }
7347
7348 int qty = type->gun->recoil;
7349 if( ammo_data() ) {
7350 qty += ammo_data()->ammo->recoil;
7351 }
7352
7353 return qty * gun_recoil_multiplier( bipod );
7354}

References itype::ammo, ammo_data(), ammo_remaining(), ammo_required(), itype::gun, gun_recoil_multiplier(), is_gun(), and type.

Referenced by calculate_dispersion(), npc::confident_gun_mode_range(), ranged::fire_gun(), and gun_info().

◆ gun_recoil_multiplier()

double item::gun_recoil_multiplier ( bool  bipod = false) const

Get multiplier on recoil considering handling and attached gunmods.

Parameters
bipodwhether any bipods should be considered
Returns
multiplier on recoil applied to shots fired from this gun

Definition at line 7322 of file item.cpp.

7323{
7324 double handling = type->gun->handling;
7325 for( const item *mod : gunmods() ) {
7326 if( bipod || !mod->has_flag( flag_BIPOD ) ) {
7327 handling += mod->type->gunmod->handling;
7328 }
7329 }
7330
7331 // Rescale from JSON units which are intentionally specified as integral values
7332 handling /= 10;
7333
7334 // Handling will almost always be above 1.0
7335 if( handling > 1.0 ) {
7336 return 1.0 / handling;
7337 } else {
7338 return 2.0 - handling;
7339 }
7340}

References flag_BIPOD(), itype::gun, gunmods(), and type.

Referenced by gun_info(), and gun_recoil().

◆ gun_set_mode()

bool item::gun_set_mode ( const gun_mode_id mode)

Try to set the mode for a gun, returning false if no such mode is possible.

Definition at line 7928 of file item.cpp.

7929{
7930 if( !is_gun() || is_gunmod() || !gun_all_modes().count( mode ) ) {
7931 return false;
7932 }
7933 set_var( GUN_MODE_VAR_NAME, mode.str() );
7934 return true;
7935}

References count(), gun_all_modes(), GUN_MODE_VAR_NAME(), is_gun(), is_gunmod(), set_var(), and string_id< T >::str().

Referenced by target_ui::action_switch_mode(), gun_cycle_mode(), avatar_funcs::gunmod_remove(), game::handle_action(), io(), and gun_actor::shoot().

◆ gun_skill()

skill_id item::gun_skill ( ) const

◆ gunmod_find() [1/2]

item * item::gunmod_find ( const itype_id mod)

Get first attached gunmod matching type or nullptr if no such mod or item is not a gun.

Definition at line 7763 of file item.cpp.

7764{
7765 std::vector<item *> mods = gunmods();
7766 auto it = std::find_if( mods.begin(), mods.end(), [&mod]( item * e ) {
7767 return e->typeId() == mod;
7768 } );
7769 return it != mods.end() ? *it : nullptr;
7770}

References gunmods().

Referenced by saw_barrel_actor::can_use_on(), saw_stock_actor::can_use_on(), cycle_action(), gunmod_find(), is_gunmod_compatible(), tname(), volume(), and weight().

◆ gunmod_find() [2/2]

const item * item::gunmod_find ( const itype_id mod) const

Definition at line 7772 of file item.cpp.

7773{
7774 return const_cast<item *>( this )->gunmod_find( mod );
7775}
item * gunmod_find(const itype_id &mod)
Get first attached gunmod matching type or nullptr if no such mod or item is not a gun.
Definition: item.cpp:7763

References gunmod_find().

◆ gunmod_info()

void item::gunmod_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 2384 of file item.cpp.

2386{
2387 if( !is_gunmod() ) {
2388 return;
2389 }
2390 const islot_gunmod &mod = *type->gunmod;
2391
2392 if( is_gun() && parts->test( iteminfo_parts::DESCRIPTION_GUNMOD ) ) {
2393 info.push_back( iteminfo( "DESCRIPTION",
2394 _( "This mod <info>must be attached to a gun</info>, "
2395 "it can not be fired separately." ) ) );
2396 }
2398 info.push_back( iteminfo( "DESCRIPTION",
2399 _( "When attached to a gun, <good>allows</good> making "
2400 "<info>reach melee attacks</info> with it." ) ) );
2401 }
2402 if( mod.dispersion != 0 && parts->test( iteminfo_parts::GUNMOD_DISPERSION ) ) {
2403 info.push_back( iteminfo( "GUNMOD", _( "Dispersion modifier: " ), "",
2405 mod.dispersion ) );
2406 }
2407 if( mod.sight_dispersion != -1 && parts->test( iteminfo_parts::GUNMOD_DISPERSION_SIGHT ) ) {
2408 info.push_back( iteminfo( "GUNMOD", _( "Sight dispersion: " ), "",
2409 iteminfo::lower_is_better, mod.sight_dispersion ) );
2410 }
2411 if( mod.aim_speed >= 0 && parts->test( iteminfo_parts::GUNMOD_AIMSPEED ) ) {
2412 info.push_back( iteminfo( "GUNMOD", _( "Aim speed: " ), "",
2413 iteminfo::lower_is_better, mod.aim_speed ) );
2414 }
2415 int total_damage = static_cast<int>( mod.damage.total_damage() );
2416 if( total_damage != 0 && parts->test( iteminfo_parts::GUNMOD_DAMAGE ) ) {
2417 info.push_back( iteminfo( "GUNMOD", _( "Damage: " ), "", iteminfo::show_plus,
2418 total_damage ) );
2419 }
2420 int pierce = get_ranged_pierce( mod );
2422 info.push_back( iteminfo( "GUNMOD", _( "Armor-pierce: " ), "", iteminfo::show_plus,
2423 pierce ) );
2424 }
2425 if( mod.handling != 0 && parts->test( iteminfo_parts::GUNMOD_HANDLING ) ) {
2426 info.emplace_back( "GUNMOD", _( "Handling modifier: " ), "",
2427 iteminfo::show_plus, mod.handling );
2428 }
2429 if( !type->mod->ammo_modifier.empty() && parts->test( iteminfo_parts::GUNMOD_AMMO ) ) {
2430 for( const ammotype &at : type->mod->ammo_modifier ) {
2431 info.push_back( iteminfo( "GUNMOD", string_format( _( "Ammo: <stat>%s</stat>" ),
2432 at->name() ) ) );
2433 }
2434 }
2435 if( mod.reload_modifier != 0 && parts->test( iteminfo_parts::GUNMOD_RELOAD ) ) {
2436 info.emplace_back( "GUNMOD", _( "Reload modifier: " ), _( "<num>%" ),
2437 iteminfo::lower_is_better, mod.reload_modifier );
2438 }
2439 if( mod.min_str_required_mod > 0 && parts->test( iteminfo_parts::GUNMOD_STRENGTH ) ) {
2440 info.push_back( iteminfo( "GUNMOD", _( "Minimum strength required modifier: " ),
2441 mod.min_str_required_mod ) );
2442 }
2443 if( !mod.add_mod.empty() && parts->test( iteminfo_parts::GUNMOD_ADD_MOD ) ) {
2445
2446 std::string mod_loc_str = _( "<bold>Adds mod locations: </bold> " );
2447
2448 std::map<gunmod_location, int> mod_locations = mod.add_mod;
2449
2450 int iternum = 0;
2451 for( std::pair<const gunmod_location, int> &elem : mod_locations ) {
2452 if( iternum != 0 ) {
2453 mod_loc_str += "; ";
2454 }
2455 mod_loc_str += string_format( "<bold>%s</bold> %s", elem.second, elem.first.name() );
2456 iternum++;
2457 }
2458 mod_loc_str += ".";
2459 info.push_back( iteminfo( "GUNMOD", mod_loc_str ) );
2460 }
2461
2463
2464 if( parts->test( iteminfo_parts::GUNMOD_USEDON ) ) {
2465 std::string used_on_str = _( "<bold>Used on:</bold>" );
2466
2467 if( !mod.usable.empty() ) {
2468 used_on_str += _( "\n Specific: " ) + enumerate_as_string( mod.usable.begin(),
2469 mod.usable.end(), []( const itype_id & used_on ) {
2470 return string_format( "<info>%s</info>", used_on->nname( 1 ) );
2471 } );
2472 }
2473
2474 if( !mod.usable_category.empty() ) {
2475 used_on_str += _( "\n Category: " );
2476 std::vector<std::string> combination;
2477 for( const std::unordered_set<weapon_category_id> &catgroup : mod.usable_category ) {
2478 combination.emplace_back( ( "[" ) + enumerate_as_string( catgroup.begin(),
2479 catgroup.end(), []( const weapon_category_id & wcid ) {
2480 return string_format( "<info>%s</info>", wcid->name().translated() );
2481 }, enumeration_conjunction::none ) + ( "]" ) );
2482 }
2483 used_on_str += enumerate_as_string( combination, enumeration_conjunction::or_ );
2484 }
2485
2486 info.push_back( iteminfo( "GUNMOD", used_on_str ) );
2487 }
2488
2489 if( parts->test( iteminfo_parts::GUNMOD_LOCATION ) ) {
2490 info.push_back( iteminfo( "GUNMOD", string_format( _( "Location: %s" ),
2491 mod.location.name() ) ) );
2492 }
2493
2494 if( !mod.blacklist_mod.empty() && parts->test( iteminfo_parts::GUNMOD_BLACKLIST_MOD ) ) {
2495 std::string mod_black_str = _( "<bold>Incompatible with mod location: </bold> " );
2496
2497 int iternum = 0;
2498 for( const gunmod_location &black : mod.blacklist_mod ) {
2499 if( iternum != 0 ) {
2500 mod_black_str += ", ";
2501 }
2502 mod_black_str += string_format( "%s", black.name() );
2503 iternum++;
2504 }
2505 mod_black_str += ".";
2506 info.push_back( iteminfo( "GUNMOD", mod_black_str ) );
2507 }
2508}
cata::value_ptr< islot_gunmod > gunmod
Definition: itype.h:831
cata::value_ptr< islot_mod > mod
Definition: itype.h:826

References _, catacurses::black, DESCRIPTION_GUNMOD, DESCRIPTION_GUNMOD_REACH, enumerate_as_string(), flag_REACH_ATTACK(), get_ranged_pierce(), itype::gunmod, GUNMOD_ADD_MOD, GUNMOD_AIMSPEED, GUNMOD_AMMO, GUNMOD_ARMORPIERCE, GUNMOD_BLACKLIST_MOD, GUNMOD_DAMAGE, GUNMOD_DISPERSION, GUNMOD_DISPERSION_SIGHT, GUNMOD_HANDLING, GUNMOD_LOCATION, GUNMOD_RELOAD, GUNMOD_STRENGTH, GUNMOD_USEDON, has_flag(), info(), insert_separation_line(), is_gun(), is_gunmod(), iteminfo::lower_is_better, itype::mod, ammunition_type::name(), none, or_, iteminfo::show_plus, string_format(), iteminfo_query::test(), and type.

Referenced by info().

◆ gunmods() [1/2]

◆ gunmods() [2/2]

std::vector< const item * > item::gunmods ( ) const

Definition at line 7758 of file item.cpp.

7759{
7760 return contents.gunmods();
7761}

References contents, and item_contents::gunmods().

◆ handle_craft_failure()

bool item::handle_craft_failure ( player crafter)

Handle failure during crafting.

Destroy components, lose progress, and set a new failure point.

Parameters
crafterthe crafting player.
Returns
whether the craft being worked on should be entirely destroyed

Definition at line 931 of file crafting.cpp.

932{
933 if( !is_craft() ) {
934 debugmsg( "handle_craft_failure() called on non-craft '%s.' Aborting.", tname() );
935 return false;
936 }
937
938 const double success_roll = crafter.crafting_success_roll( get_making() );
939 const int starting_components = this->components.size();
940 // Destroy at most 75% of the components, always a chance of losing 1 though
941 const size_t max_destroyed = std::max<size_t>( 1, components.size() * 3 / 4 );
942 for( size_t i = 0; i < max_destroyed; i++ ) {
943 // This shouldn't happen
944 if( components.empty() ) {
945 break;
946 }
947 // If we roll success, skip destroying a component
948 if( x_in_y( success_roll, 1.0 ) ) {
949 continue;
950 }
951 destroy_random_component( *this, crafter );
952 }
953 if( starting_components > 0 && this->components.empty() ) {
954 // The craft had components and all of them were destroyed.
955 return true;
956 }
957
958 // Minimum 25% progress lost, average 35%. Falls off exponentially
959 // Loss is scaled by the success roll
960 const double percent_progress_loss = rng_exponential( 0.25, 0.35 ) *
961 ( 1.0 - std::min( success_roll, 1.0 ) );
962 const int progess_loss = item_counter * percent_progress_loss;
963 crafter.add_msg_player_or_npc( _( "You mess up and lose %d%% progress." ),
964 _( "<npcname> messes up and loses %d%% progress." ), progess_loss / 100000 );
965 item_counter = clamp( item_counter - progess_loss, 0, 10000000 );
966
967 set_next_failure_point( crafter );
968
969 // Check if we can consume a new component and continue
970 if( !crafter.can_continue_craft( *this ) ) {
971 crafter.cancel_activity();
972 }
973 return false;
974}
bool x_in_y(const time_duration &a, const time_duration &b)
Definition: calendar.cpp:521
constexpr T clamp(const T &val, const T &min, const T &max)
Clamp first argument so that it is no lower than second and no higher than third.
Definition: cata_utility.h:149
void cancel_activity()
Definition: character.cpp:9235
const recipe & get_making() const
Get the stored recipe for in progress crafts.
Definition: item.cpp:10119
void set_next_failure_point(const player &crafter)
Calculates and sets the next failure point for an in progress craft.
Definition: crafting.cpp:905
void add_msg_player_or_npc(const std::string &player_msg, const std::string &npc_str) const override
Definition: player.cpp:372
bool can_continue_craft(item &craft)
Check if the player meets the requirements to continue the in progress craft and if unable to continu...
Definition: crafting.cpp:1169
double crafting_success_roll(const recipe &making) const
Calculate a value representing the success of the player at crafting the given recipe,...
Definition: crafting.cpp:821
static void destroy_random_component(item &craft, const player &crafter)
Definition: crafting.cpp:918
double rng_exponential(double min, double mean)
Definition: rng.cpp:55

References _, player::add_msg_player_or_npc(), player::can_continue_craft(), Character::cancel_activity(), clamp(), components, player::crafting_success_roll(), debugmsg, destroy_random_component(), get_making(), is_craft(), item_counter, rng_exponential(), set_next_failure_point(), tname(), and x_in_y().

◆ handle_pickup_ownership()

void item::handle_pickup_ownership ( Character c)

Definition at line 4497 of file item.cpp.

4498{
4499 if( is_owned_by( c ) ) {
4500 return;
4501 }
4502 // Add ownership to item if unowned
4503 if( owner.is_null() ) {
4504 set_owner( c );
4505 } else {
4507 if( !is_owned_by( c ) && &c == &you ) {
4508 std::vector<npc *> witnesses;
4509 for( npc &elem : g->all_npcs() ) {
4510 if( rl_dist( elem.pos(), you.pos() ) < MAX_VIEW_DISTANCE && elem.get_faction() &&
4511 is_owned_by( elem ) && elem.sees( you.pos() ) ) {
4512 elem.say( "<witnessed_thievery>", 7 );
4513 npc *npc_to_add = &elem;
4514 witnesses.push_back( npc_to_add );
4515 }
4516 }
4517 if( !witnesses.empty() ) {
4519 // Make sure there is only one witness
4520 for( npc &guy : g->all_npcs() ) {
4521 if( guy.get_attitude() == NPCATT_RECOVER_GOODS ) {
4522 guy.set_attitude( NPCATT_NULL );
4523 }
4524 }
4525 random_entry( witnesses )->set_attitude( NPCATT_RECOVER_GOODS );
4526 // Notify the activity that we got a witness
4527 if( c.activity && !c.activity.is_null() && c.activity.id() == ACT_PICKUP ) {
4528 c.activity.str_values.clear();
4529 c.activity.str_values.emplace_back( has_thievery_witness );
4530 }
4531 }
4532 set_owner( c );
4533 }
4534 }
4535}
const tripoint & pos() const override
Definition: character.cpp:602
bool is_owned_by(const Character &c, bool available_to_take=false) const
Definition: item.cpp:1238
void set_old_owner(const faction_id &temp_owner)
Definition: item.h:2029
void set_owner(const faction_id &new_owner)
Definition: item.h:2035
Definition: npc.h:744
int rl_dist(const coords::coord_point< Point, Origin, Scale > &loc1, const coords::coord_point< Point, Origin, Scale > &loc2)
Definition: coordinates.h:519
static constexpr int MAX_VIEW_DISTANCE
static const activity_id ACT_PICKUP("ACT_PICKUP")
static const std::string has_thievery_witness("has_thievery_witness")
@ NPCATT_NULL
Definition: npc.h:81
@ NPCATT_RECOVER_GOODS
Definition: npc.h:100

References ACT_PICKUP, c, g, get_owner(), get_player_character(), has_thievery_witness(), string_id< T >::is_null(), is_owned_by(), MAX_VIEW_DISTANCE, NPCATT_NULL, NPCATT_RECOVER_GOODS, owner, Character::pos(), random_entry(), rl_dist(), set_old_owner(), and set_owner().

Referenced by on_pickup(), on_wear(), and on_wield().

◆ has_any_flag()

template<typename Container , typename T = std::decay_t<decltype( *std::declval<const Container &>().begin() )>>
bool item::has_any_flag ( const Container &  flags) const
inline

Definition at line 1417 of file item.h.

1417 {
1418 return std::any_of( flags.begin(), flags.end(), [&]( const T & flag ) {
1419 return has_flag( flag );
1420 } );
1421 }

Referenced by Character::can_eat(), and Character::consume_effects().

◆ has_clothing_mod()

bool item::has_clothing_mod ( ) const

Definition at line 10163 of file item.cpp.

10164{
10165 for( const clothing_mod &cm : clothing_mods::get_all() ) {
10166 if( has_own_flag( cm.flag ) ) {
10167 return true;
10168 }
10169 }
10170 return false;
10171}
const std::vector< clothing_mod > & get_all()

References clothing_mods::get_all(), and has_own_flag().

Referenced by tname().

◆ has_effect_when_carried()

bool item::has_effect_when_carried ( art_effect_passive  effect) const

Does the item provide the artifact effect when it is carried?

Definition at line 9787 of file item.cpp.

9788{
9789 if( !type->artifact ) {
9790 return false;
9791 }
9792 const std::vector<art_effect_passive> &ec = type->artifact->effects_carried;
9793 if( std::find( ec.begin(), ec.end(), effect ) != ec.end() ) {
9794 return true;
9795 }
9796 for( const item *i : contents.all_items_top() ) {
9797 if( i->has_effect_when_carried( effect ) ) {
9798 return true;
9799 }
9800 }
9801 return false;
9802}
Definition: effect.h:164
FMT_CONSTEXPR bool find(Ptr first, Ptr last, T value, Ptr &out)
cata::value_ptr< islot_artifact > artifact
Definition: itype.h:837

References item_contents::all_items_top(), itype::artifact, contents, detail::find(), and type.

Referenced by Character::hardcoded_effects(), and Character::has_artifact_with().

◆ has_effect_when_wielded()

bool item::has_effect_when_wielded ( art_effect_passive  effect) const

Does the item provide the artifact effect when it is wielded?

Definition at line 9769 of file item.cpp.

9770{
9771 if( !type->artifact ) {
9772 return false;
9773 }
9774 const std::vector<art_effect_passive> &ew = type->artifact->effects_wielded;
9775 return std::find( ew.begin(), ew.end(), effect ) != ew.end();
9776}

References itype::artifact, detail::find(), and type.

Referenced by Character::hardcoded_effects().

◆ has_effect_when_worn()

bool item::has_effect_when_worn ( art_effect_passive  effect) const

Does the item provide the artifact effect when it is worn?

Definition at line 9778 of file item.cpp.

9779{
9780 if( !type->artifact ) {
9781 return false;
9782 }
9783 const std::vector<art_effect_passive> &ew = type->artifact->effects_worn;
9784 return std::find( ew.begin(), ew.end(), effect ) != ew.end();
9785}

References itype::artifact, detail::find(), and type.

◆ has_explosion_data()

bool item::has_explosion_data ( ) const

Definition at line 6852 of file item.cpp.

6853{
6854 return is_fuel() ? type->fuel->has_explode_data : false;
6855}

References itype::fuel, is_fuel(), and type.

Referenced by vehicle::explode_fuel().

◆ has_fault()

bool item::has_fault ( const fault_id fault) const

Does this item have the specified fault.

Definition at line 5319 of file item.cpp.

5320{
5321 return faults.count( fault );
5322}
Definition: fault.h:29

References faults.

Referenced by install_bionic_actor::can_use(), color_in_inventory(), bionic_install_preset::get_denial(), bionic_install_surgeon_preset::get_denial(), ranged::handle_gun_damage(), bionic_sterilize_preset::is_shown(), and tname().

◆ has_flag() [1/2]

bool item::has_flag ( const flag_str_id flag) const

Definition at line 5353 of file item.cpp.

5354{
5355 return has_flag( flag.str() );
5356}

References has_flag(), and string_id< T >::str().

◆ has_flag() [2/2]

bool item::has_flag ( const std::string &  flag) const

Definition at line 5329 of file item.cpp.

5330{
5331 bool ret = false;
5332
5333 if( json_flag::get( f ).inherit() ) {
5334 for( const item *e : is_gun() ? gunmods() : toolmods() ) {
5335 // gunmods fired separately do not contribute to base gun flags
5336 if( !e->is_gun() && e->has_flag( f ) ) {
5337 return true;
5338 }
5339 }
5340 }
5341
5342 // other item type flags
5343 ret = type->has_flag( f );
5344 if( ret ) {
5345 return ret;
5346 }
5347
5348 // now check for item specific flags
5349 ret = has_own_flag( f );
5350 return ret;
5351}
bool has_flag(const std::string &flag) const
Definition: itype.cpp:146

References json_flag::get(), gunmods(), itype::has_flag(), has_own_flag(), is_gun(), cata::hash64_detail::ret, toolmods(), and type.

Referenced by Character::activate_bionic(), map::add_item(), map::add_item_or_charges(), monexamine::add_leash(), Character::all_items_with_flag(), Character::allergy_type(), npc::alt_attack(), ammo_consume(), ammo_remaining(), ammo_required(), ammo_set(), amount_of_internal(), Character::armor_absorb(), armor_fit_info(), armor_info(), iexamine::autodoc(), autodoc_internal(), basic_info(), mattack::bio_op_disarm(), iuse::blech(), Character::block_hit(), blocking_ability(), Character::burn_fuel(), butcher_time_to_cut(), butchery_drops_harvest(), calc_rot(), iuse::camera(), item_funcs::can_be_unloaded(), Character::can_consume(), can_do_activity_there(), Character::can_eat(), Character::can_feed_furnace_with(), behavior::character_oracle_t::can_make_fire(), repair_item_actor::can_repair_target(), can_revive(), Character::can_swap(), Character::can_takeoff(), Character::can_unwield(), Character::can_use_heal_item(), Character::can_wear(), Character::can_wield(), iuse::capture_monster_act(), iuse::capture_monster_veh(), cast_spell(), check_litcig(), anonymous_namespace{armor_layers.cpp}::clothing_flags_description(), anonymous_namespace{armor_layers.cpp}::clothing_layer(), color_in_inventory(), combat_info(), comestible_inventory_preset::comestible_inventory_preset(), complete_craft(), crafting::complete_disassemble(), Character::compute_effective_nutrients(), Character::compute_nutrient_range(), conductive(), consider_butchery(), Character::consume_charges(), game_menus::inv::consume_drink(), Character::consume_effects(), game_menus::inv::consume_food(), Character::consume_med(), Character::consume_remote_fuel(), vehicle::consumption_per_hour(), corpse_volume(), activity_handlers::cracking_do_turn(), recipe::create_byproducts(), Single_item_creator::create_single(), iexamine::cvdmachine(), cycle_action(), damage_melee(), repair_item_actor::default_action(), iexamine::dimensional_portal(), display_name(), aim_activity_actor::do_turn(), draw_bionics_titlebar(), game::dump_stats(), durability_indicator(), Character::eat(), einkpc_download_memory_card(), iuse::einktabletpc(), emit_radio_signal(), final_info(), character_funcs::find_ammo_helper(), find_auto_consume(), find_food_heater(), Character::find_remote_fuel(), findBestGasDiscount(), ranged::fire_gun(), activity_handlers::fish_do_turn(), character_funcs::fmt_wielded_weapon(), food_info(), inventory::form_from_map(), Character::fun_for(), activity_handlers::game_do_turn(), character_funcs::get_book_fun_for(), activatable_inventory_preset::get_denial(), bionic_sterilize_preset::get_denial(), get_encumber_when_containing(), ranged::get_fastest_sight(), Character::get_fuel_available(), get_layer(), zone_manager::get_near_zone_type_for_item(), get_sizing(), ranged::get_str_draw_penalty(), getlight_emit(), give_item_to(), goes_bad(), gun_info(), iuse::gun_repair(), gunmod_info(), ranged::gunmode_checks_common(), ranged::gunmode_checks_weapon(), iuse::hand_crank(), ranged::handle_gun_damage(), Character::handle_melee_wear(), handle_problematic_pickup(), Character::has_enough_charges(), has_flag(), Character::has_item_with_flag(), Character::head_cloth_encumbrance(), iuse_transform::info(), inherit_flags(), npc_trading::init_buying(), init_memory_card_with_random_stuff(), target_ui::init_window_and_input(), monexamine::insert_battery(), is_ammo_belt(), is_armor(), is_corpse(), is_dangerous(), advanced_inventory_pane::is_filtered(), is_filthy(), is_firearm(), character_funcs::is_fun_to_read(), is_gunmod_compatible(), is_irremovable(), vehicle::is_perpetual_type(), is_pet_armor(), is_power_armor(), is_reloadable(), is_salvageable(), bionic_uninstall_preset::is_shown(), is_two_handed(), is_unarmed_weapon(), ma_requirements::is_valid_character(), ma_requirements::is_valid_weapon(), is_worn_only_with(), item(), Character::item_reload_cost(), mdeath::jabberwock(), layer_item(), magazine_info(), item_action_generator::map_actions_to_items(), Character::meets_stat_requirements(), Character::melee_attack(), melee_skill(), Character::melee_special_effects(), npc_ai::melee_value(), mine_activity(), Item_modifier::modify(), Character::modify_morale(), avatar_action::move(), game_menus::inv::multiwash(), Character::mutation_effect(), iexamine::nanofab(), needs_processing(), iuse::note_bionics(), on_wear(), on_wield(), iuse::pack_cbm(), Character::passive_power_gen(), monexamine::pet_menu(), avatar_action::plthrow(), iuse::poison(), item_category::priority_zone(), process_extinguish(), process_internal(), Character::process_items(), process_litcig(), process_tool(), process_UPS(), process_vehicle_items(), vehicle_part::properties_to_item(), mattack::pull_metal_weapon(), activity_handlers::pulp_do_turn(), item_reload_option::qty(), iuse::radio_mod(), iuse::radiocar(), iuse::radiocontrol(), rate_food(), rcdrive(), reach_range(), ready_to_revive(), reinforceable(), avatar_action::reload(), reload(), activity_handlers::reload_finish(), remove_ammo(), remove_radio_mod(), repair_item_actor::repair(), repaired_with(), game::revive_corpse(), iexamine::safe(), character_funcs::select_ammo(), set_relative_rot(), player_morale::set_worn(), sight_dispersion(), iexamine::sign(), smoker_load_food(), map::spawn_item(), activity_handlers::spellcasting_finish(), activity_handlers::start_fire_do_turn(), starting_clothes(), starting_inv(), ranged::str_draw_damage_modifier(), ranged::str_draw_dispersion_modifier(), ranged::str_draw_range_modifier(), ranged::throw_item(), tname(), tool_info(), iuse::toolmod_attach(), iuse::towel_common(), type_name(), Character::unarmed_attack(), units_remaining(), avatar_funcs::unload_item(), charger_tile::update_internal(), iuse_transform::use(), set_transform_iuse::use(), unpack_actor::use(), cast_spell_actor::use(), Character::use_charges(), iexamine::use_furn_fake_item(), avatar_action::use_item(), avatar_funcs::use_item(), vehicle::use_washing_machine(), npc::value(), volume(), martialart::weapon_valid(), npc::wear_if_wanted(), Character::wear_item(), iuse::weather_tool(), weight(), weather_effect::wet_player(), npc::will_accept_from_player(), and Character::will_eat().

◆ has_infinite_charges()

bool item::has_infinite_charges ( ) const

Definition at line 9991 of file item.cpp.

9992{
9993 return charges == INFINITE_CHARGES;
9994}

References charges, and INFINITE_CHARGES.

Referenced by display_name(), liquid_handler::get_liquid_target(), mod_charges(), and Character::will_eat().

◆ has_label()

bool item::has_label ( ) const

Returns true if item has "item_label" itemvar.

Definition at line 9977 of file item.cpp.

9978{
9979 return has_var( "item_label" );
9980}

References has_var().

Referenced by label().

◆ has_own_flag()

bool item::has_own_flag ( const std::string &  flag) const

Checks whether item itself has given flag (doesn't check item type or gunmods).

Essentially get_flags().count(f). Works faster than has_flag

Definition at line 5324 of file item.cpp.

5325{
5326 return item_tags.count( f );
5327}
size_type count(const T &t) const
Definition: flat_set.h:141

References cata::flat_set< T, Compare, Data >::count(), and item_tags.

Referenced by Character::can_eat(), Character::can_wear(), color_in_inventory(), final_info(), has_clothing_mod(), has_flag(), mod_last_rot_check(), on_drop(), tname(), update_clothing_mod_val(), and sew_advanced_actor::use().

◆ has_property()

bool item::has_property ( const std::string &  prop) const

Definition at line 5384 of file item.cpp.

5385{
5386 return type->properties.find( prop ) != type->properties.end();
5387}

References itype::properties, and type.

Referenced by iuse::capture_monster_act(), and ranged::throw_item().

◆ has_rotten_away()

bool item::has_rotten_away ( ) const

Whether the item has enough rot that it should get removed.

Regular shelf life perishable foods rot away completely at 2x shelf life. Corpses last 10 days

Returns
true if the item has enough rot to be removed, false otherwise.

Definition at line 8812 of file item.cpp.

8813{
8814 if( is_corpse() && !can_revive() ) {
8815 return get_rot() > 10_days;
8816 } else {
8817 return is_food() && get_relative_rot() > 2.0;
8818 }
8819}
time_duration get_rot() const
Definition: item.h:860

References can_revive(), get_relative_rot(), get_rot(), is_corpse(), and is_food().

Referenced by process_rot().

◆ has_technique()

bool item::has_technique ( const matec_id tech) const

Whether the item supports a specific martial art technique (either through its type, or through its individual techniques).

Definition at line 5465 of file item.cpp.

5466{
5467 return type->techniques.count( tech ) > 0 || techniques.count( tech ) > 0;
5468}

References techniques, itype::techniques, and type.

Referenced by blocking_ability(), effective_dps(), character_martial_arts::has_technique(), and mdeath::jabberwock().

◆ has_tools_to_continue()

bool item::has_tools_to_continue ( ) const

Definition at line 10136 of file item.cpp.

10137{
10138 assert( craft_data_ );
10139 return craft_data_->tools_to_continue;
10140}

References craft_data_.

◆ has_use()

bool item::has_use ( ) const

Returns true if the item has any use function.

Definition at line 7960 of file item.cpp.

7961{
7962 return type->has_use();
7963}
bool has_use() const
Definition: itype.cpp:141

References itype::has_use(), and type.

Referenced by find_auto_consume().

◆ has_var()

◆ ideal_ranged_dps()

double item::ideal_ranged_dps ( const Character who,
gun_mode mode 
) const

Definition at line 2080 of file npcmove.cpp.

2081{
2082 if( !is_gun() ) {
2083 return 0;
2084 }
2086 if( ammo_current() ) {
2087 itype_id ammo = ammo_current();
2088 gun_damage.add( ammo->ammo->damage );
2089 } else if( ammo_default() ) {
2090 itype_id ammo = ammo_default();
2091 gun_damage.add( ammo->ammo->damage );
2092 }
2093 float damage_factor = gun_damage.total_damage();
2094 damage_factor *= mode.qty;
2095
2096 int move_cost = ranged::time_to_attack( who, *this, item_location() );
2097 if( ammo_remaining() == 0 ) {
2098 int reload_cost = get_reload_time() + who.encumb( bp_hand_l ) + who.encumb( bp_hand_r );
2099 // HACK: Doesn't check how much ammo they'll actually get from the reload. Because we don't know.
2100 // DPS is less impacted the larger the magazine being swapped.
2101 reload_cost /= magazine_integral() ? 1 : ammo_capacity() / mode.qty;
2102 move_cost += reload_cost;
2103 }
2104 std::vector<ranged::aim_type> aim_types = ranged::get_aim_types( who, *this );
2105 auto regular = std::find_if( aim_types.begin(),
2106 aim_types.end(), []( ranged::aim_type at ) {
2107 return at.action == std::string( "AIMED_SHOT" );
2108 } );
2109 if( regular == aim_types.end() ) {
2110 debugmsg( "Could not find REGULAR aim type for gun %s", tname() );
2111 return 0;
2112 }
2113 move_cost += ranged::gun_engagement_moves( who, *this, ( *regular ).threshold );
2114
2115 double dps = damage_factor / ( move_cost / 100.0f );
2116
2117 return dps;
2118}
static int move_cost(const item &it, const tripoint &src, const tripoint &dest)
int qty
burst size for is_gun() firearms, or melee range for is_melee() weapons
Definition: gun_mode.h:21
A lightweight handle to an item independent of it's location Unlike a raw pointer can be (de-)seriali...
Definition: item_location.h:23
int get_reload_time() const
Returns the reload time of the gun.
Definition: item.cpp:6554
void regular(const queued_explosion &qe)
Definition: explosion.cpp:1467
int time_to_attack(const Character &p, const item &firing, const item_location loc)
Calculates time taken to fire gun.
Definition: ranged.cpp:1735
void add(const damage_instance &added_di)
Definition: damage.cpp:93

References damage_instance::add(), itype::ammo, ammo_capacity(), ammo_current(), ammo_default(), ammo_remaining(), bp_hand_l, bp_hand_r, debugmsg, dps(), Character::encumb(), ranged::get_aim_types(), get_reload_time(), gun_damage(), ranged::gun_engagement_moves(), is_gun(), magazine_integral(), move_cost(), gun_mode::qty, explosion_handler::explosion_funcs::regular(), ranged::time_to_attack(), tname(), and damage_instance::total_damage().

Referenced by npc::check_or_use_weapon_cbm(), and npc_ai::gun_value().

◆ in_container()

item item::in_container ( const itype_id container_type) const

Definition at line 850 of file item.cpp.

851{
852 if( !cont.is_null() ) {
853 item ret( cont, birthday() );
854 ret.put_in( *this );
855 if( made_of( LIQUID ) && ret.is_container() ) {
856 // Note: we can't use any of the normal container functions as they check the
857 // container being suitable (seals, watertight etc.)
858 ret.contents.back().charges = charges_per_volume( ret.get_container_capacity() );
859 }
860
861 ret.invlet = invlet;
862 return ret;
863 } else {
864 return *this;
865 }
866}
char invlet
Definition: item.h:2246

References birthday(), charges_per_volume(), invlet, string_id< T >::is_null(), LIQUID, made_of(), and cata::hash64_detail::ret.

Referenced by in_its_container().

◆ in_its_container()

item item::in_its_container ( ) const

Returns this item into its default container.

If it does not have a default container, returns this. It's intended to be used like

newitem = newitem.in_its_container();

Definition at line 845 of file item.cpp.

846{
847 return in_container( type->default_container.value_or( itype_id::NULL_ID() ) );
848}
item in_container(const itype_id &container_type) const
Definition: item.cpp:850
std::optional< itype_id > default_container
Definition: itype.h:883

References itype::default_container, in_container(), string_id< itype >::NULL_ID(), and type.

Referenced by defense_game::caravan(), crafting::complete_disassemble(), Single_item_creator::create_single(), map::spawn_an_item(), starting_inv(), and debug_menu::wishitem().

◆ inc_damage() [1/2]

bool item::inc_damage ( )

same as other inc_damage, but uses DT_NULL as damage type.

Definition at line 6284 of file item.cpp.

6285{
6286 return inc_damage( DT_NULL );
6287}
bool inc_damage()
same as other inc_damage, but uses DT_NULL as damage type.
Definition: item.cpp:6284

References DT_NULL, and inc_damage().

Referenced by inc_damage(), and process_blackpowder_fouling().

◆ inc_damage() [2/2]

bool item::inc_damage ( damage_type  dt)

Increment item damage by itype::damage_scale constrained by max_damage.

Parameters
dttype of damage which may be passed to on_damage callback
Returns
whether item should be destroyed

Definition at line 6279 of file item.cpp.

6280{
6281 return mod_damage( itype::damage_scale, dt );
6282}
bool mod_damage(int qty, damage_type dt)
Apply damage to const itemrained by min_damage and max_damage.
Definition: item.cpp:6252
static constexpr int damage_scale
Definition: itype.h:979

References itype::damage_scale, and mod_damage().

Referenced by iuse::blood_draw(), damage_item(), iuse::firecracker_pack_act(), activity_handlers::gunmod_add_finish(), ranged::handle_gun_damage(), Character::handle_melee_wear(), activity_handlers::lockpicking_finish(), and vehicle::operate_scoop().

◆ info() [1/4]

std::vector< iteminfo > item::info ( ) const

Return all the information about the item and its type as a vector.

This includes the different properties of the itype (if they are visible to the player).

Parameters
partscontrols which parts of the iteminfo to return.
batchThe batch crafting number to multiply data by
Returns
The properties (encapsulated into iteminfo) are added to this vector, the vector can be used to compare them to properties of another item.

Definition at line 3992 of file item.cpp.

3993{
3995}
static const iteminfo_query no_conditions

References info(), iteminfo_query::no_conditions, and TEMP_NORMAL.

Referenced by advanced_inventory::action_examine(), ammo_info(), animal_armor_info(), armor_fit_info(), armor_info(), armor_protection_info(), basic_info(), battery_info(), bionic_info(), book_info(), combat_info(), game_menus::inv::compare(), component_info(), container_info(), contents_info(), disassembly_info(), final_info(), food_info(), gun_info(), gunmod_info(), info(), info_string(), game::list_items(), magazine_info(), med_info(), qualities_info(), wish_item_callback::refresh(), repair_info(), examine_item_menu::run(), trading_window::show_item_data(), and tool_info().

◆ info() [2/4]

std::vector< iteminfo > item::info ( const iteminfo_query parts,
int  batch,
temperature_flag  temperature 
) const

Definition at line 4007 of file item.cpp.

4009{
4010 const bool debug = g != nullptr && debug_mode;
4011
4012 // TODO: Use reference properly
4013 const iteminfo_query *parts = &parts_ref;
4014 std::vector<iteminfo> info;
4015
4016 if( !is_null() ) {
4017 basic_info( info, parts, batch, debug );
4018 }
4019
4020 const item *med_item = nullptr;
4021 if( is_medication() ) {
4022 med_item = this;
4023 } else if( is_med_container() ) {
4024 med_item = &contents.front();
4025 }
4026 if( med_item != nullptr ) {
4027 med_info( med_item, info, parts, batch, debug );
4028 }
4029
4030 if( const item *food_item = get_food() ) {
4031 food_info( food_item, info, parts, batch, debug, temperature );
4032 }
4033
4034 container_info( info, parts, batch, debug );
4035 contents_info( info, parts, batch, debug );
4036 combat_info( info, parts, batch, debug );
4037
4038 magazine_info( info, parts, batch, debug );
4039 ammo_info( info, parts, batch, debug );
4040
4041 const item *gun = nullptr;
4042 if( is_gun() ) {
4043 gun = this;
4044 const gun_mode aux = gun_current_mode();
4045 // if we have an active auxiliary gunmod display stats for this instead
4046 if( aux && aux->is_gunmod() && aux->is_gun() &&
4048 gun = &*aux;
4049 info.emplace_back( "DESCRIPTION",
4050 string_format( _( "Stats of the active <info>gunmod (%s)</info> "
4051 "are shown." ), gun->tname() ) );
4052 }
4053 }
4054 if( gun != nullptr ) {
4055 gun_info( gun, info, parts, batch, debug );
4056 }
4057
4058 gunmod_info( info, parts, batch, debug );
4059 armor_info( info, parts, batch, debug );
4060 animal_armor_info( info, parts, batch, debug );
4061 book_info( info, parts, batch, debug );
4062 battery_info( info, parts, batch, debug );
4063 tool_info( info, parts, batch, debug );
4064 component_info( info, parts, batch, debug );
4065 qualities_info( info, parts, batch, debug );
4066
4067 // Uses for item (bandaging quality, holster capacity, grenade activation)
4069 for( const std::pair<const std::string, use_function> &method : type->use_methods ) {
4071 method.second.dump_info( *this, info );
4072 }
4073 }
4074
4075 repair_info( info, parts, batch, debug );
4076 disassembly_info( info, parts, batch, debug );
4077
4078 final_info( info, parts_ref, batch, debug );
4079
4080 if( !info.empty() && info.back().sName == "--" ) {
4081 info.pop_back();
4082 }
4083
4084 return info;
4085}
void gunmod_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:2384
gun_mode gun_current_mode() const
Get the current mode for this gun (or an invalid mode if item is not a gun)
Definition: item.cpp:7915
void contents_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3564
void animal_armor_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:2736
void med_info(const item *med_item, std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:1645
void disassembly_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3195
void combat_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3419
bool is_med_container() const
Definition: item.cpp:6641
void qualities_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3249
void gun_info(const item *mod, std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:2021
void component_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3150
void repair_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3174
void magazine_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:1885
void food_info(const item *food_item, std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug, temperature_flag temperature) const
Definition: item.cpp:1674
void armor_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:2553
void battery_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3083
void ammo_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:1908
void basic_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:1462
void final_info(std::vector< iteminfo > &info, const iteminfo_query &parts, int batch, bool debug) const
Definition: item.cpp:3647
void book_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:2918
void tool_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3102
void container_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3055
@ DESCRIPTION_AUX_GUNMOD_HEADER

References _, ammo_info(), animal_armor_info(), armor_info(), basic_info(), battery_info(), book_info(), combat_info(), component_info(), container_info(), contents, contents_info(), debug, debug_mode, DESCRIPTION_AUX_GUNMOD_HEADER, DESCRIPTION_USE_METHODS, disassembly_info(), final_info(), food_info(), item_contents::front(), g, get_food(), gun_current_mode(), gun_info(), gunmod_info(), info(), insert_separation_line(), is_gun(), is_gunmod(), is_med_container(), is_medication(), is_null(), magazine_info(), med_info(), qualities_info(), repair_info(), string_format(), iteminfo_query::test(), tname(), tool_info(), type, and itype::use_methods.

◆ info() [3/4]

std::vector< iteminfo > item::info ( int  batch) const

Definition at line 3997 of file item.cpp.

References info(), iteminfo_query::no_conditions, and TEMP_NORMAL.

◆ info() [4/4]

std::vector< iteminfo > item::info ( temperature_flag  temperature) const

Definition at line 4002 of file item.cpp.

4003{
4004 return info( iteminfo_query::all, 1, temperature );
4005}
static const iteminfo_query all

References iteminfo_query::all, and info().

◆ info_string() [1/2]

std::string item::info_string ( ) const

As info, but as a string rather than a vector of properties.

Definition at line 4087 of file item.cpp.

4088{
4089 return info_string( iteminfo_query::all, 1 );
4090}

References iteminfo_query::all, and info_string().

Referenced by battery_info(), colorized_item_description(), draw_caravan_items(), and info_string().

◆ info_string() [2/2]

std::string item::info_string ( const iteminfo_query parts,
int  batch = 1,
temperature_flag  temperature = temperature_flag::TEMP_NORMAL 
) const

Definition at line 4092 of file item.cpp.

4094{
4095 std::vector<iteminfo> item_info = info( parts, batch, temperature );
4096 return format_item_info( item_info, {} );
4097}
std::string format_item_info(const std::vector< iteminfo > &item_display, const std::vector< iteminfo > &item_compare)
Definition: output.cpp:854

References format_item_info(), and info().

◆ inherit_flags() [1/2]

void item::inherit_flags ( const item parent,
const recipe making 
)

Inherit applicable flags from the given parent item.

Parameters
parentItem to inherit from

Definition at line 985 of file crafting.cpp.

986{
987 // default behavior is to resize the clothing, which happens elsewhere
988 if( making.has_flag( flag_NO_RESIZE ) ) {
989 //If item is crafted from poor-fit components, the result is poorly fitted too
990 if( parent.has_flag( flag_VARSIZE ) ) {
992 }
993 //If item is crafted from perfect-fit components, the result is perfectly fitted too
994 if( parent.has_flag( flag_FIT ) ) {
996 }
997 }
998 for( const std::string &f : parent.item_tags ) {
999 if( json_flag::get( f ).craft_inherit() ) {
1000 set_flag( f );
1001 }
1002 }
1003 for( const std::string &f : parent.type->get_flags() ) {
1004 if( json_flag::get( f ).craft_inherit() ) {
1005 set_flag( f );
1006 }
1007 }
1008 if( parent.has_flag( flag_HIDDEN_POISON ) ) {
1009 poison = parent.poison;
1010 }
1011}
int poison
Definition: item.h:2214
bool has_flag(const std::string &flag_name) const
Definition: recipe.cpp:95
static const std::string flag_NO_RESIZE("NO_RESIZE")
static const std::string flag_HIDDEN_POISON("HIDDEN_POISON")
static const std::string flag_FIT("FIT")
static const std::string flag_VARSIZE("VARSIZE")

References flag_FIT(), flag_HIDDEN_POISON(), flag_NO_RESIZE(), flag_VARSIZE(), json_flag::get(), itype::get_flags(), has_flag(), recipe::has_flag(), item_tags, poison, set_flag(), type, and unset_flag().

Referenced by complete_craft(), and inherit_flags().

◆ inherit_flags() [2/2]

void item::inherit_flags ( const std::list< item > &  parents,
const recipe making 
)

Inherit applicable flags from the given list of parent items.

Parameters
parentsItems to inherit from

Definition at line 1013 of file crafting.cpp.

1014{
1015 for( const item &parent : parents ) {
1016 inherit_flags( parent, making );
1017 }
1018}
void inherit_flags(const item &parent, const recipe &making)
Inherit applicable flags from the given parent item.
Definition: crafting.cpp:985
std::vector< item * > parents(const item &it)
Returns vector of parent containers (if any) starting with the innermost.
Definition: visitable.cpp:74

References inherit_flags(), and visitable< item >::parents().

◆ io()

template<typename Archive >
void item::io ( Archive &  archive)

Definition at line 2189 of file savegame_json.cpp.

2190{
2191
2192 itype_id orig; // original ID as loaded from JSON
2193 const auto load_type = [&]( const std::string & id ) {
2194 orig = itype_id( id );
2195 convert( item_controller->migrate_id( orig ) );
2196 };
2197
2198 const auto load_curammo = [this]( const std::string & id ) {
2199 curammo = &*item_controller->migrate_id( itype_id( id ) );
2200 };
2201 const auto load_corpse = [this]( const std::string & id ) {
2202 if( itype_id( id ).is_null() ) {
2203 // backwards compatibility, nullptr should not be stored at all
2204 corpse = nullptr;
2205 } else {
2206 corpse = &mtype_id( id ).obj();
2207 }
2208 };
2209 archive.template io<const itype>( "typeid", type, load_type, []( const itype & i ) {
2210 return i.get_id().str();
2211 }, io::required_tag() );
2212
2213 // normalize legacy saves to always have charges >= 0
2214 archive.io( "charges", charges, 0 );
2215 charges = std::max( charges, 0 );
2216
2217 archive.io( "energy", energy, 0_J );
2218
2219 archive.io( "burnt", burnt, 0 );
2220 archive.io( "poison", poison, 0 );
2221 archive.io( "frequency", frequency, 0 );
2222 archive.io( "snip_id", snip_id, snippet_id::NULL_ID() );
2223 // NB! field is named `irridation` in legacy files
2224 archive.io( "irridation", irradiation, 0 );
2225 archive.io( "bday", bday, calendar::start_of_cataclysm );
2226 archive.io( "mission_id", mission_id, -1 );
2227 archive.io( "player_id", player_id, -1 );
2228 archive.io( "item_vars", item_vars, io::empty_default_tag() );
2229 // TODO: change default to empty string
2230 archive.io( "name", corpse_name, std::string() );
2231 archive.io( "owner", owner, owner.NULL_ID() );
2232 archive.io( "old_owner", old_owner, old_owner.NULL_ID() );
2233 archive.io( "invlet", invlet, '\0' );
2234 archive.io( "damaged", damage_, 0 );
2235 archive.io( "active", active, false );
2236 archive.io( "is_favorite", is_favorite, false );
2237 archive.io( "item_counter", item_counter, static_cast<decltype( item_counter )>( 0 ) );
2238 archive.io( "rot", rot, 0_turns );
2239 archive.io( "last_rot_check", last_rot_check, calendar::start_of_cataclysm );
2240 archive.io( "techniques", techniques, io::empty_default_tag() );
2241 archive.io( "faults", faults, io::empty_default_tag() );
2242 archive.io( "item_tags", item_tags, io::empty_default_tag() );
2243 archive.io( "components", components, io::empty_default_tag() );
2244 archive.io( "recipe_charges", recipe_charges, 1 );
2245 archive.template io<const itype>( "curammo", curammo, load_curammo,
2246 []( const itype & i ) {
2247 return i.get_id().str();
2248 } );
2249 archive.template io<const mtype>( "corpse", corpse, load_corpse,
2250 []( const mtype & i ) {
2251 return i.id.str();
2252 } );
2253 archive.io( "craft_data", craft_data_, decltype( craft_data_ )() );
2254 archive.io( "light", light.luminance, nolight.luminance );
2255 archive.io( "light_width", light.width, nolight.width );
2256 archive.io( "light_dir", light.direction, nolight.direction );
2257
2258 static const cata::value_ptr<relic> null_relic_ptr = nullptr;
2259 archive.io( "relic_data", relic_data, null_relic_ptr );
2260
2261 archive.io( "drop_token", drop_token, decltype( drop_token )() );
2262
2263 item_controller->migrate_item( orig, *this );
2264
2265 if( !Archive::is_input::value ) {
2266 return;
2267 }
2268 /* Loading has finished, following code is to ensure consistency and fixes bugs in saves. */
2269
2271
2272 double float_damage = 0;
2273 if( archive.read( "damage", float_damage ) ) {
2274 damage_ = std::min( std::max( min_damage(),
2275 static_cast<int>( float_damage * itype::damage_scale ) ),
2276 max_damage() );
2277 }
2278
2279 int note = 0;
2280 const bool note_read = archive.read( "note", note );
2281
2282 // Old saves used to only contain one of those values (stored under "poison"), it would be
2283 // loaded into a union of those members. Now they are separate members and must be set separately.
2284 if( poison != 0 && note == 0 && !type->snippet_category.empty() ) {
2285 std::swap( note, poison );
2286 }
2287 if( poison != 0 && frequency == 0 && ( typeId() == itype_radio_on || typeId() == itype_radio ) ) {
2289 }
2290 if( poison != 0 && irradiation == 0 && typeId() == itype_rad_badge ) {
2292 }
2293
2294 // erase all invalid flags (not defined in flags.json), display warning about invalid flags
2295 erase_if( item_tags, [&]( const std::string & f ) {
2296 if( !json_flag::get( f ).id.is_valid() ) {
2297 debugmsg( "item of type '%s' was loaded with undefined flag '%s'.", typeId().c_str(), f );
2298 return true;
2299 } else {
2300 return false;
2301 }
2302 } );
2303
2304 if( note_read ) {
2306 } else {
2307 std::optional<std::string> snip;
2308 if( archive.read( "snippet_id", snip ) && snip ) {
2309 snip_id = snippet_id( snip.value() );
2310 }
2311 }
2312
2313 // Compatibility for item type changes: for example soap changed from being a generic item
2314 // (item::charges -1 or 0 or anything else) to comestible (and thereby counted by charges),
2315 // old saves still have invalid charges, this fixes the charges value to the default charges.
2316 if( count_by_charges() && charges <= 0 ) {
2318 }
2319 if( is_food() ) {
2320 active = true;
2321 }
2322 if( !active && item_tags.count( "WET" ) > 0 ) {
2323 // Some wet items from legacy saves may be inactive
2324 active = true;
2325 }
2326 std::string mode;
2327 if( archive.read( "mode", mode ) ) {
2328 // only for backward compatibility (nowadays mode is stored in item_vars)
2329 gun_set_mode( gun_mode_id( mode ) );
2330 }
2331
2332 // Books without any chapters don't need to store a remaining-chapters
2333 // counter, it will always be 0 and it prevents proper stacking.
2334 if( get_chapters() == 0 ) {
2335 for( auto it = item_vars.begin(); it != item_vars.end(); ) {
2336 if( it->first.compare( 0, 19, "remaining-chapters-" ) == 0 ) {
2337 item_vars.erase( it++ );
2338 } else {
2339 ++it;
2340 }
2341 }
2342 }
2343
2344 // Remove stored translated gerund in favor of storing the inscription tool type
2345 item_vars.erase( "item_label_type" );
2346 item_vars.erase( "item_note_type" );
2347
2348 // Activate corpses from old saves
2349 if( is_corpse() && !active ) {
2350 active = true;
2351 }
2352
2353 if( charges != 0 && !type->can_have_charges() ) {
2354 // Types that are known to have charges, but should not have them.
2355 // We fix it here, but it's expected from bugged saves and does not require a message.
2356 if( charge_removal_blacklist::get().count( type->get_id() ) == 0 ) {
2357 debugmsg( "Item %s was loaded with charges, but can not have any!", type->get_id() );
2358 }
2359 charges = 0;
2360 }
2361
2362 // Relic check. Kinda late, but that's how relics have to be
2363 if( relic_data ) {
2364 relic_data->check();
2365 }
2366}
bool erase_if(Col &set, Pred predicate)
Erases elements from a set that match given predicate function.
Definition: cata_utility.h:237
int player_id
Definition: item.h:2220
int mission_id
Definition: item.h:2219
int frequency
Definition: item.h:2215
int recipe_charges
Definition: item.h:2212
snippet_id migrate_hash_to_id(int hash)
Used only for legacy compatibility.
light_emission nolight
Definition: item.cpp:316
void swap(colony< element_type, element_allocator_type, element_skipfield_type > &a, colony< element_type, element_allocator_type, element_skipfield_type > &b) COLONY_NOEXCEPT_SWAP(element_allocator_type)
Swaps colony A's contents with that of colony B.
Definition: colony.h:3496
const std::set< itype_id > & get()
static void load_legacy_craft_data(io::JsonObjectInputArchive &archive, T &value)
static const itype_id itype_radio("radio")
static const itype_id itype_radio_on("radio_on")
static const itype_id itype_rad_badge("rad_badge")
Tag that indicates the value of the io is some kind of container and its default value is to be empty...
Definition: cata_io.h:105
Tag that indicates the value is required and must exists in the JSON data.
Definition: cata_io.h:110
bool can_have_charges() const
Definition: itype.cpp:214
mtype_id id
Definition: mtype.h:240
string_id< translation > snippet_id
Definition: type_id.h:205

References active, bday, burnt, itype::can_have_charges(), charges, components, convert(), corpse, corpse_name, count(), cata::flat_set< T, Compare, Data >::count(), count_by_charges(), craft_data_, curammo, damage_, itype::damage_scale, debugmsg, light_emission::direction, energy, erase_if(), faults, frequency, charge_removal_blacklist::get(), json_flag::get(), get_chapters(), itype::get_id(), gun_set_mode(), base_camps::id, itype::id, invlet, irradiation, is_corpse(), is_favorite, is_food(), item(), item_controller, item_counter, item_tags, item_vars, itype_id, itype_rad_badge, itype_radio, itype_radio_on, last_rot_check, light, load_legacy_craft_data(), light_emission::luminance, max_damage(), snippet_library::migrate_hash_to_id(), min_damage(), mission_id, mtype_id, nolight, string_id< translation >::NULL_ID(), string_id< T >::NULL_ID(), old_owner, owner, player_id, poison, recipe_charges, relic_data, snip_id, SNIPPET, itype::snippet_category, calendar::start_of_cataclysm, string_id< T >::str(), cata::swap(), techniques, type, typeId(), and light_emission::width.

Referenced by deserialize(), and serialize().

◆ is_ammo()

◆ is_ammo_belt()

bool item::is_ammo_belt ( ) const

Definition at line 6593 of file item.cpp.

6594{
6595 return is_magazine() && has_flag( flag_MAG_BELT );
6596}
static const std::string flag_MAG_BELT("MAG_BELT")

References flag_MAG_BELT(), has_flag(), and is_magazine().

Referenced by Character::can_reload(), item_reload_option::item_reload_option(), avatar_action::reload(), reload(), and avatar_funcs::unload_item().

◆ is_ammo_container()

◆ is_armor()

◆ is_artifact()

bool item::is_artifact ( ) const

Definition at line 6994 of file item.cpp.

6995{
6996 return !!type->artifact;
6997}

References itype::artifact, and type.

Referenced by game::add_artifact_dreams(), iuse::artifact(), needs_processing(), and process_artifact().

◆ is_bandolier()

bool item::is_bandolier ( ) const

◆ is_battery()

bool item::is_battery ( ) const

Definition at line 6588 of file item.cpp.

6589{
6590 return !!type->battery;
6591}

References itype::battery, and type.

Referenced by battery_info(), display_name(), energy_remaining(), and mod_energy().

◆ is_bionic()

◆ is_book()

◆ is_brewable()

bool item::is_brewable ( ) const

Definition at line 6629 of file item.cpp.

6630{
6631 return !!type->brewable;
6632}

References itype::brewable, and type.

Referenced by brewing_results(), brewing_time(), final_info(), iexamine::fvat_empty(), and iexamine::fvat_full().

◆ is_bucket()

bool item::is_bucket ( ) const

Definition at line 6760 of file item.cpp.

6761{
6762 // That "preserves" part is a hack:
6763 // Currently all non-empty cans are effectively sealed at all times
6764 // Making them buckets would cause weirdness
6765 return type->container &&
6766 type->container->watertight &&
6767 !type->container->seals &&
6768 !type->container->unseals_into;
6769}

References itype::container, and type.

Referenced by can_unload_liquid(), get_remaining_capacity_for_liquid(), is_bucket_nonempty(), is_container_eligible_for_crafting(), is_funnel_container(), pick_one_up(), and iexamine::tree_maple_tapped().

◆ is_bucket_nonempty()

bool item::is_bucket_nonempty ( ) const

◆ is_comestible()

◆ is_container()

◆ is_container_empty()

◆ is_container_full()

bool item::is_container_full ( bool  allow_bucket = false) const

Whether this item has no more free capacity for its current content.

Parameters
allow_bucketAllow filling non-sealable containers

Definition at line 6868 of file item.cpp.

6869{
6870 if( is_container_empty() ) {
6871 return false;
6872 }
6873 return get_remaining_capacity_for_liquid( contents.front(), allow_bucket ) == 0;
6874}

References contents, item_contents::front(), get_remaining_capacity_for_liquid(), and is_container_empty().

Referenced by is_container_eligible_for_crafting(), is_reloadable_helper(), and avatar_action::reload().

◆ is_corpse()

bool item::is_corpse ( ) const

Whether this is a corpse item.

Corpses always have valid monster type (corpse) associated (get_mtype return a non-null pointer) and have been created with make_corpse.

Definition at line 6646 of file item.cpp.

6647{
6648 return corpse != nullptr && has_flag( flag_CORPSE );
6649}

References corpse, flag_CORPSE(), and has_flag().

Referenced by base_volume(), burn(), activity_handlers::butcher_finish(), calc_rot(), can_revive(), color(), color_in_inventory(), component_info(), zone_manager::get_near_zone_type_for_item(), get_shelf_life(), goes_bad(), has_rotten_away(), io(), made_of(), on_damage(), process_internal(), map::process_items_in_vehicle(), processing_speed(), game::revive_corpse(), tname(), volume(), and weight().

◆ is_craft()

◆ is_dangerous()

bool item::is_dangerous ( ) const

Definition at line 9831 of file item.cpp.

9832{
9833 if( has_flag( flag_DANGEROUS ) ) {
9834 return true;
9835 }
9836
9837 // Note: Item should be dangerous regardless of what type of a container is it
9838 // Visitable interface would skip some options
9839 for( const item *it : contents.all_items_top() ) {
9840 if( it->is_dangerous() ) {
9841 return true;
9842 }
9843 }
9844 return false;
9845}
static const std::string flag_DANGEROUS("DANGEROUS")

References item_contents::all_items_top(), contents, flag_DANGEROUS(), and has_flag().

Referenced by give_item_to(), and npc::value().

◆ is_deployable()

bool item::is_deployable ( ) const

Definition at line 6979 of file item.cpp.

6980{
6981 return type->can_use( "deploy_furn" );
6982}

References itype::can_use(), and type.

Referenced by Character::invoke_item().

◆ is_emissive()

bool item::is_emissive ( ) const

Whether the item emits any light at all.

Definition at line 6974 of file item.cpp.

6975{
6976 return light.luminance > 0 || type->light_emission > 0;
6977}

References light, itype::light_emission, light_emission::luminance, and type.

Referenced by submap::load(), map::update_lum(), and submap::update_lum_add().

◆ is_engine()

bool item::is_engine ( ) const

Definition at line 6776 of file item.cpp.

6777{
6778 return !!type->engine;
6779}

References itype::engine, and type.

Referenced by is_faulty(), and tname().

◆ is_faulty()

bool item::is_faulty ( ) const

Definition at line 6796 of file item.cpp.

6797{
6798 return is_engine() ? !faults.empty() : false;
6799}
bool is_engine() const
Definition: item.cpp:6776

References faults, and is_engine().

Referenced by clear_faults(), and vehicle_part::name().

◆ is_filthy()

bool item::is_filthy ( ) const

Marks the item as filthy, so characters with squeamish trait can't wear it.

Definition at line 10011 of file item.cpp.

10012{
10013 return has_flag( flag_FILTHY ) && ( get_option<bool>( "FILTHY_MORALE" ) ||
10015}
static const std::string flag_FILTHY("FILTHY")
static const trait_id trait_SQUEAMISH("SQUEAMISH")

References flag_FILTHY(), get_avatar(), has_flag(), Character::has_trait(), and trait_SQUEAMISH.

Referenced by Character::can_wear(), color_in_inventory(), crafting::complete_disassemble(), salvage_actor::cut_up(), repair_item_actor::handle_components(), item_category::priority_zone(), activity_handlers::reload_finish(), tname(), avatar_funcs::unload_item(), and heal_actor::use().

◆ is_firearm()

bool item::is_firearm ( ) const

Does it require gunsmithing tools to repair.

Definition at line 6548 of file item.cpp.

6549{
6550 static const std::string primitive_flag( "PRIMITIVE_RANGED_WEAPON" );
6551 return is_gun() && !has_flag( primitive_flag );
6552}

References has_flag(), and is_gun().

Referenced by repair_item_actor::can_repair_target(), iuse::gun_clean(), iuse::gun_repair(), and repair_inventory_preset::is_shown().

◆ is_food()

◆ is_food_container()

bool item::is_food_container ( ) const

◆ is_fresh()

bool item::is_fresh ( ) const
inline

an item is fresh if it is capable of rotting but still has a long shelf life remaining

Definition at line 839 of file item.h.

839 {
840 return goes_bad() && get_relative_rot() < 0.1;
841 }

Referenced by comestible_inventory_preset::get_freshness(), get_freshness_description(), and tname().

◆ is_fuel()

bool item::is_fuel ( ) const

Definition at line 6786 of file item.cpp.

6787{
6788 return !!type->fuel;
6789}

References itype::fuel, and type.

Referenced by Character::can_fuel_bionic_with(), vehicle_part::consume_energy(), fuel_energy(), fuel_pump_terrain(), and has_explosion_data().

◆ is_funnel_container()

bool item::is_funnel_container ( units::volume bigger_than) const

Funnel related functions.

See weather.cpp for their usage.

Definition at line 6954 of file item.cpp.

6955{
6956 if( !is_bucket() && !is_watertight_container() ) {
6957 return false;
6958 }
6959 // TODO: consider linking funnel to item or -making- it an active item
6960 if( get_container_capacity() <= bigger_than ) {
6961 return false; // skip contents check, performance
6962 }
6963 if(
6964 contents.empty() ||
6968 bigger_than = get_container_capacity();
6969 return true;
6970 }
6971 return false;
6972}
bool is_watertight_container() const
Whether this is a container which can be used to store liquids.
Definition: item.cpp:6750
static const itype_id itype_water_acid_weak("water_acid_weak")
static const itype_id itype_water_acid("water_acid")
static const itype_id itype_water("water")

References contents, item_contents::empty(), item_contents::front(), get_container_capacity(), is_bucket(), is_watertight_container(), itype_water, itype_water_acid, itype_water_acid_weak, and typeId().

◆ is_going_bad()

bool item::is_going_bad ( ) const
inline

an item is about to become rotten when shelf life has nearly elapsed

Definition at line 844 of file item.h.

844 {
845 return get_relative_rot() > 0.9;
846 }

Referenced by get_freshness_description(), comestible_inventory_preset::get_time_left_rounded(), and tname().

◆ is_gun()

bool item::is_gun ( ) const

Can this item be used to perform a ranged attack?

See also
item::is_melee()
Note
an item can be both a gun and melee weapon concurrently

Definition at line 6543 of file item.cpp.

6544{
6545 return !!type->gun;
6546}

References itype::gun, and type.

Referenced by vehicle::add_item(), ranged::aim_per_move(), allow_crafting_component(), ammo_capacity(), ammo_consume(), character_funcs::ammo_count_for(), ammo_data(), ammo_effects(), ammo_info(), ammo_remaining(), ammo_required(), ammo_set(), ammo_sort_name(), ammo_types(), ammo_unset(), npc_ai::best_mode_for_range(), can_fire_turret(), avatar_action::can_fire_weapon(), saw_barrel_actor::can_use_on(), saw_stock_actor::can_use_on(), defense_game::caravan(), casings_handle(), npc::character_danger(), npc::check_or_use_weapon_cbm(), color_in_inventory(), npc::confident_shoot_range(), contents_info(), contextualize_skill(), damage_melee(), display_name(), durability_indicator(), final_info(), character_funcs::find_ammo_helper(), character_funcs::find_reloadables(), fire(), ranged::fire_gun(), avatar_action::fire_wielded_weapon(), character_funcs::fmt_wielded_weapon(), npc::form_opinion(), ranged::get_aim_types(), get_covered_body_parts(), get_encumber_when_containing(), get_free_mod_locations(), ranged::get_most_accurate_sight(), get_reload_time(), give_item_to(), gun_all_modes(), gun_cycle_mode(), gun_damage(), gun_dispersion(), gun_get_mode(), gun_get_mode_id(), gun_noise(), gun_range(), gun_recoil(), gun_set_mode(), gun_skill(), gunmod_info(), game::handle_action(), ranged::handle_gun_damage(), has_flag(), Character::i_add(), ideal_ranged_dps(), info(), character_effects::intimidation(), is_firearm(), is_gunmod_compatible(), is_reloadable(), gunmod_inventory_preset::is_shown(), saw_barrel_inventory_preset::is_shown(), saw_stock_inventory_preset::is_shown(), vehicle_part::is_turret(), Character::item_reload_cost(), Character::item_store_cost(), magazine_compatible(), magazine_default(), magazine_integral(), Item_modifier::modify(), item_reload_option::moves(), Character::on_dodge(), on_wield(), parse_tags(), tutorial_game::post_action(), Character::power_rating(), reach_range(), activity_handlers::reload_finish(), remove_ammo(), item_funcs::shots_remaining(), sight_dispersion(), starting_inv(), tname(), game::try_get_right_click_action(), character_funcs::try_wield_contents(), npc::value(), visit_internal(), volume(), weapon_inventory_preset::weapon_inventory_preset(), weight(), and npc::wield_better_weapon().

◆ is_gunmod()

◆ is_gunmod_compatible()

ret_val< bool > item::is_gunmod_compatible ( const item mod) const

Definition at line 7777 of file item.cpp.

7778{
7779 if( !mod.is_gunmod() ) {
7780 debugmsg( "Tried checking compatibility of non-gunmod" );
7782 }
7783 const islot_gunmod &g_mod = *mod.type->gunmod;
7784
7785 if( !is_gun() ) {
7786 return ret_val<bool>::make_failure( _( "isn't a weapon" ) );
7787
7788 } else if( is_gunmod() ) {
7789 return ret_val<bool>::make_failure( _( "is a gunmod and cannot be modded" ) );
7790
7791 } else if( gunmod_find( mod.typeId() ) ) {
7792 return ret_val<bool>::make_failure( _( "already has a %s" ), mod.tname( 1 ) );
7793
7794 } else if( !get_mod_locations().count( g_mod.location ) ) {
7795 return ret_val<bool>::make_failure( _( "doesn't have a slot for this mod" ) );
7796
7797 } else if( get_free_mod_locations( g_mod.location ) <= 0 ) {
7798 return ret_val<bool>::make_failure( _( "doesn't have enough room for another %s mod" ),
7799 mod.type->gunmod->location.name() );
7800
7801 } else if( !g_mod.usable.empty() || !g_mod.usable_category.empty() ) {
7802 bool usable = g_mod.usable.count( this->typeId() );
7803 for( const std::unordered_set<weapon_category_id> &mod_cat : g_mod.usable_category ) {
7804 if( usable ) {
7805 break;
7806 }
7807 if( std::all_of( mod_cat.begin(), mod_cat.end(), [this]( const weapon_category_id & wcid ) {
7808 return this->type->weapon_category.count( wcid );
7809 } ) ) {
7810 usable = true;
7811 }
7812 }
7813 if( !usable ) {
7814 return ret_val<bool>::make_failure( _( "cannot have a %s" ), mod.tname() );
7815 }
7816
7817 } else if( g_mod.location.str() == "underbarrel" &&
7819 return ret_val<bool>::make_failure( _( "can only accept small mods on that slot" ) );
7820
7821 } else if( !mod.type->mod->acceptable_ammo.empty() ) {
7822 bool compat_ammo = false;
7823 for( const ammotype &at : mod.type->mod->acceptable_ammo ) {
7824 if( ammo_types( false ).count( at ) ) {
7825 compat_ammo = true;
7826 }
7827 }
7828 if( !compat_ammo ) {
7830 _( "%1$s cannot be used on item with no compatible ammo types" ), mod.tname( 1 ) );
7831 }
7832 } else if( mod.typeId() == itype_waterproof_gunmod && has_flag( flag_WATERPROOF_GUN ) ) {
7833 return ret_val<bool>::make_failure( _( "is already waterproof" ) );
7834
7835 } else if( mod.typeId() == itype_tuned_mechanism && has_flag( flag_NEVER_JAMS ) ) {
7836 return ret_val<bool>::make_failure( _( "is already eminently reliable" ) );
7837
7838 } else if( mod.typeId() == itype_brass_catcher && has_flag( flag_RELOAD_EJECT ) ) {
7839 return ret_val<bool>::make_failure( _( "cannot have a brass catcher" ) );
7840
7841 } else if( ( !mod.type->mod->ammo_modifier.empty() || !mod.type->mod->magazine_adaptor.empty() )
7842 && ( ammo_remaining() > 0 || magazine_current() ) ) {
7843 return ret_val<bool>::make_failure( _( "must be unloaded before installing this mod" ) );
7844 }
7845
7846 for( const gunmod_location &slot : mod.type->gunmod->blacklist_mod ) {
7847 if( get_mod_locations().count( slot ) ) {
7848 return ret_val<bool>::make_failure( _( "cannot be installed on a weapon with \"%s\"" ),
7849 slot.name() );
7850 }
7851 }
7852
7854}
std::string name() const
Returns the translated name.
Definition: itype.cpp:15
std::string str() const
Returns the location id.
Definition: itype.h:86
static ret_val make_success(T val=default_success::value)
Definition: ret_val.h:42
static ret_val make_failure(T val=default_failure::value)
Definition: ret_val.h:46
static const std::string flag_RELOAD_EJECT("RELOAD_EJECT")
static const itype_id itype_brass_catcher("brass_catcher")
static const itype_id itype_waterproof_gunmod("waterproof_gunmod")
static const itype_id itype_tuned_mechanism("tuned_mechanism")
static const std::string flag_PUMP_ACTION("PUMP_ACTION")
static const std::string flag_NEVER_JAMS("NEVER_JAMS")
static const std::string flag_WATERPROOF_GUN("WATERPROOF_GUN")
static const std::string flag_PUMP_RAIL_COMPATIBLE("PUMP_RAIL_COMPATIBLE")
gunmod_location location
Where is this gunmod installed (e.g.
Definition: itype.h:549
std::vector< std::unordered_set< weapon_category_id > > usable_category
Definition: itype.h:553
std::unordered_set< itype_id > usable
What kind of weapons can this gunmod be used with (e.g.
Definition: itype.h:552

References _, ammo_remaining(), ammo_types(), count(), debugmsg, flag_NEVER_JAMS(), flag_PUMP_ACTION(), flag_PUMP_RAIL_COMPATIBLE(), flag_RELOAD_EJECT(), flag_WATERPROOF_GUN(), get_free_mod_locations(), get_mod_locations(), gunmod_find(), has_flag(), is_gun(), is_gunmod(), itype_brass_catcher, itype_tuned_mechanism, itype_waterproof_gunmod, islot_gunmod::location, magazine_current(), ret_val< T >::make_failure(), ret_val< T >::make_success(), gunmod_location::name(), gunmod_location::str(), typeId(), islot_gunmod::usable, and islot_gunmod::usable_category.

Referenced by gunmod_inventory_preset::get_denial(), avatar_funcs::gunmod_add(), and activity_handlers::gunmod_add_finish().

◆ is_holster()

bool item::is_holster ( ) const

Definition at line 6603 of file item.cpp.

6604{
6605 return type->can_use( "holster" );
6606}

References itype::can_use(), and type.

Referenced by character_funcs::find_reloadables(), and get_total_capacity().

◆ is_irremovable()

bool item::is_irremovable ( ) const

Definition at line 6801 of file item.cpp.

6802{
6803 return has_flag( flag_IRREMOVABLE );
6804}
static const std::string flag_IRREMOVABLE("IRREMOVABLE")

References flag_IRREMOVABLE(), and has_flag().

Referenced by allow_crafting_component(), detach_gunmods_actor::can_use(), remove_ammo(), and detach_gunmods_actor::use().

◆ is_magazine()

◆ is_map()

bool item::is_map ( ) const

Definition at line 6740 of file item.cpp.

6741{
6742 return get_category().get_id() == itemcat_maps;
6743}
item_category_id get_id() const
static const item_category_id itemcat_maps("maps")

References get_category(), item_category::get_id(), and itemcat_maps.

Referenced by map::add_item(), and display_name().

◆ is_med_container()

bool item::is_med_container ( ) const

Definition at line 6641 of file item.cpp.

6642{
6643 return !contents.empty() && contents.front().is_medication();
6644}

References contents, item_contents::empty(), item_contents::front(), and is_medication().

Referenced by info().

◆ is_medication()

◆ is_melee() [1/2]

bool item::is_melee ( ) const

Is this item an effective melee weapon for any damage type?

See also
item::is_gun()
Note
an item can be both a gun and melee weapon concurrently

Definition at line 6693 of file item.cpp.

6694{
6695 for( int idx = DT_NULL + 1; idx != NUM_DT; ++idx ) {
6696 if( is_melee( static_cast<damage_type>( idx ) ) ) {
6697 return true;
6698 }
6699 }
6700 return false;
6701}

References DT_NULL, is_melee(), and NUM_DT.

Referenced by contextualize_skill(), is_melee(), melee_skill(), and on_wield().

◆ is_melee() [2/2]

bool item::is_melee ( damage_type  dt) const

Is this item an effective melee weapon for the given damage type?

Definition at line 6703 of file item.cpp.

6704{
6705 return damage_melee( dt ) > MELEE_STAT;
6706}
static constexpr int MELEE_STAT

References damage_melee(), and MELEE_STAT.

Referenced by iexamine::cvdmachine(), Character::i_add(), tutorial_game::post_action(), and npc::wield_better_weapon().

◆ is_money()

bool item::is_money ( ) const

Definition at line 6026 of file item.cpp.

6027{
6028 return ammo_types().count( ammotype( "money" ) );
6029}

References ammo_types().

Referenced by ammo_set(), display_name(), inventory_selector_preset::get_caption(), selection_column_preset::get_caption(), operator<(), and stacks_with().

◆ is_non_resealable_container()

bool item::is_non_resealable_container ( ) const

Whether removing this item's contents will permanently alter it.

Definition at line 6755 of file item.cpp.

6756{
6757 return type->container && !type->container->seals && type->container->unseals_into;
6758}

References itype::container, and type.

Referenced by deserialize(), advanced_inventory::move_content(), and on_contents_changed().

◆ is_null()

bool item::is_null ( ) const

Definition at line 736 of file item.cpp.

737{
738 // Actually, type should never by null at all.
739 return ( type == nullptr || type == nullitem() || typeId().is_null() );
740}

References is_null(), nullitem(), type, and typeId().

Referenced by acid_resist(), npc::address_needs(), ammo_set(), base_volume(), bash_resist(), Character::block_hit(), Character::block_ranged_hit(), bullet_resist(), Character::can_eat(), vehicle_part::can_reload(), repair_item_actor::can_repair_target(), Character::can_use(), debug_menu::character_edit_menu(), color(), colorized_feature_description_at(), veh_interact::complete_vehicle(), conductive(), Character::consume_item(), cut_resist(), damage_melee(), display_name(), anonymous_namespace{iexamine.cpp}::atm_menu::do_transfer_all_money(), anonymous_namespace{iexamine.cpp}::atm_menu::do_withdraw_money(), drop_or_embed_projectile(), enumerate_objects_around_point(), Character::extended_description(), final_info(), find_auto_consume(), fire_resist(), inventory::form_from_map(), iexamine::gaspump(), liquid_handler::get_liquid_target(), SkillLevelMap::get_skill_level(), aim_activity_actor::get_weapon(), Character::handle_melee_wear(), npc::has_healing_item(), npc::heal_player(), npc::heal_self(), info(), npc_trading::init_buying(), Character::is_armed(), is_null(), is_old_owner(), is_owned_by(), is_salvageable(), is_unarmed_weapon(), Character::item_encumb(), Character::item_reload_cost(), npc::load(), made_of(), Character::meets_requirements(), Character::melee_attack(), melee_train(), Item_modifier::modify(), explosion_handler::ExplosionProcess::move_entity(), item_location::impl::item_on_map::obtain(), item_location::impl::item_on_person::obtain(), item_location::impl::item_on_vehicle::obtain(), item_location::impl::item_in_container::obtain(), item_location::impl::item_on_map::obtain_cost(), item_location::impl::item_on_person::obtain_cost(), item_location::impl::item_on_vehicle::obtain_cost(), monexamine::pet_menu(), photo_def_for_camera_point(), player::reduce_charges(), reinforceable(), bandolier_actor::reload(), reload(), Character::roll_bash_damage(), Character::roll_cut_damage(), Character::roll_stab_damage(), projectile::set_drop(), set_snippet(), npc::shop_restock(), map::spawn_items(), starting_inv(), Character::store(), npc::store(), holster_actor::store(), Character::suffer_from_schizophrenia(), Character::throw_range(), tname(), salvage_actor::try_to_cut_up(), Character::unarmed_attack(), Character::unwield(), avatar_funcs::use_item(), npc::use_painkiller(), salvage_actor::valid_to_cut_up(), volume(), martialart::weapon_valid(), Character::wear_possessed(), weight(), npc::wield(), avatar::wield(), and npc::wield_better_weapon().

◆ is_old_owner()

bool item::is_old_owner ( const Character c,
bool  available_to_take = false 
) const

Definition at line 1253 of file item.cpp.

1254{
1255 if( get_old_owner().is_null() ) {
1256 return available_to_take;
1257 }
1258 if( !c.get_faction() ) {
1259 debugmsg( "Character %s has no faction.", c.disp_name() );
1260 return false;
1261 }
1262 return c.get_faction()->id == get_old_owner();
1263}
faction_id get_old_owner() const
Definition: item.cpp:1289

References c, debugmsg, get_old_owner(), and is_null().

◆ is_owned_by()

bool item::is_owned_by ( const Character c,
bool  available_to_take = false 
) const

Definition at line 1238 of file item.cpp.

1239{
1240 // owner.is_null() implies faction_id( "no_faction" ) which shouldn't happen, or no owner at all.
1241 // either way, certain situations this means the thing is available to take.
1242 // in other scenarios we actually really want to check for id == id, even for no_faction
1243 if( get_owner().is_null() ) {
1244 return available_to_take;
1245 }
1246 if( !c.get_faction() ) {
1247 debugmsg( "Character %s has no faction", c.disp_name() );
1248 return false;
1249 }
1250 return c.get_faction()->id == get_owner();
1251}

References c, debugmsg, get_owner(), and is_null().

Referenced by activity_on_turn_move_loot(), move_items_activity_actor::do_turn(), find_auto_consume(), handle_pickup_ownership(), npc_trading::init_buying(), pick_one_up(), pickup::pick_up(), query_consume_ownership(), and npc::wants_to_sell().

◆ is_pet_armor()

bool item::is_pet_armor ( bool  on_pet = false) const

Definition at line 6724 of file item.cpp.

6725{
6726 bool is_worn = on_pet && !get_var( "pet_armor", "" ).empty();
6727 return has_flag( flag_IS_PET_ARMOR ) && ( is_worn || !on_pet );
6728}
static const std::string flag_IS_PET_ARMOR("IS_PET_ARMOR")

References flag_IS_PET_ARMOR(), get_var(), and has_flag().

Referenced by animal_armor_info(), armor_protection_info(), get_base_env_resist(), get_base_env_resist_w_filter(), get_env_resist(), get_pet_armor_bodytype(), get_pet_armor_max_vol(), get_pet_armor_min_vol(), get_storage(), and get_thickness().

◆ is_power_armor()

bool item::is_power_armor ( ) const

Whether this is a power armor item.

Not necessarily the main armor, it could be a helmet or similar.

Definition at line 5812 of file item.cpp.

5813{
5816}
static const std::string flag_POWERARMOR_MOD("POWERARMOR_MOD")

References flag_POWERARMOR_EXO(), flag_POWERARMOR_EXTERNAL(), flag_POWERARMOR_MOD(), and has_flag().

Referenced by armor_fit_info(), Character::can_wear(), Character::consume_charges(), final_info(), Character::has_enough_charges(), process_tool(), units_remaining(), and set_transform_iuse::use().

◆ is_relic()

bool item::is_relic ( ) const

Definition at line 6999 of file item.cpp.

7000{
7001 return !!relic_data;
7002}

References relic_data.

Referenced by get_enchantments(), mutations_from_wearing(), process_relic(), and stacks_with().

◆ is_reloadable()

bool item::is_reloadable ( ) const

Is it ever possible to reload this item? Only the base item is considered with any mods ignored.

See also
player::can_reload()

Definition at line 9860 of file item.cpp.

9861{
9863 return false; // turrets ignore NO_RELOAD flag
9864
9865 } else if( is_bandolier() ) {
9866 return true;
9867
9868 } else if( is_container() ) {
9869 return true;
9870
9871 } else if( !is_gun() && !is_tool() && !is_magazine() ) {
9872 return false;
9873
9874 } else if( ammo_types().empty() ) {
9875 return false;
9876 }
9877
9878 return true;
9879}
static const std::string flag_VEHICLE("VEHICLE")

References ammo_types(), flag_NO_RELOAD(), flag_VEHICLE(), has_flag(), is_bandolier(), is_container(), is_gun(), is_magazine(), and is_tool().

Referenced by can_reload_item_or_mods(), is_reloadable_helper(), and examine_item_menu::rate_action_reload().

◆ is_reloadable_helper()

bool item::is_reloadable_helper ( const itype_id ammo,
bool  now 
) const
private

Helper for checking reloadability.

Definition at line 6902 of file item.cpp.

6903{
6904 // empty ammo is passed for listing possible ammo apparently, so it needs to return true.
6905 if( !is_reloadable() ) {
6906 return false;
6907 } else if( is_watertight_container() ) {
6908 if( ammo.is_empty() ) {
6909 return now ? !is_container_full() : true;
6910 } else if( ammo->phase != LIQUID ) {
6911 return false;
6912 } else {
6913 return now ? ( is_container_empty() || contents.front().typeId() == ammo ) : true;
6914 }
6915 } else if( magazine_integral() ) {
6916 if( !ammo.is_empty() ) {
6917 if( now && ammo_data() ) {
6918 if( ammo_current() != ammo ) {
6919 return false;
6920 }
6921 } else {
6922 const itype *at = &*ammo;
6923 if( ( !at->ammo || !ammo_types().count( at->ammo->type ) ) &&
6924 !magazine_compatible().count( ammo ) ) {
6925 return false;
6926 }
6927 }
6928 }
6929 return now ? ( ammo_remaining() < ammo_capacity() ) : true;
6930 } else {
6931 return ammo.is_empty() ? true : magazine_compatible().count( ammo );
6932 }
6933}
bool is_reloadable() const
Is it ever possible to reload this item? Only the base item is considered with any mods ignored.
Definition: item.cpp:9860
bool is_container_full(bool allow_bucket=false) const
Whether this item has no more free capacity for its current content.
Definition: item.cpp:6868

References itype::ammo, ammo_capacity(), ammo_current(), ammo_data(), ammo_remaining(), ammo_types(), contents, count(), item_contents::front(), is_container_empty(), is_container_full(), string_id< T >::is_empty(), is_reloadable(), is_watertight_container(), LIQUID, magazine_compatible(), magazine_integral(), itype::phase, and typeId().

Referenced by can_reload_with(), and is_reloadable_with().

◆ is_reloadable_with()

bool item::is_reloadable_with ( const itype_id ammo) const

Returns true if this item can be reloaded with specified ammo type at this moment.

Definition at line 6897 of file item.cpp.

6898{
6899 return is_reloadable_helper( ammo, true );
6900}

References is_reloadable_helper().

Referenced by Character::can_reload(), vehicle_part::can_reload(), fill_with(), get_remaining_capacity_for_liquid(), and reload().

◆ is_salvageable()

bool item::is_salvageable ( ) const

Definition at line 6935 of file item.cpp.

6936{
6937 if( is_null() ) {
6938 return false;
6939 }
6940 const std::vector<material_id> &mats = made_of();
6941 if( std::none_of( mats.begin(), mats.end(), []( const material_id & m ) {
6942 return m->salvaged_into().has_value();
6943 } ) ) {
6944 return false;
6945 }
6946 return !has_flag( flag_NO_SALVAGE );
6947}
static const std::string flag_NO_SALVAGE("NO_SALVAGE")

References flag_NO_SALVAGE(), has_flag(), is_null(), and made_of().

Referenced by salvage_actor::try_to_cut_up(), and salvage_actor::valid_to_cut_up().

◆ is_seed()

bool item::is_seed ( ) const

Whether this is actually a seed, the seed functions won't be of much use for non-seeds.

Definition at line 9804 of file item.cpp.

9805{
9806 return !!type->seed;
9807}

References itype::seed, and type.

Referenced by can_do_activity_there(), iexamine::dirtmound(), farm_valid_seed(), talk_function::field_plant(), plot_options::get_zone_name_suggestion(), plot_options::query_seed(), vehicle::reload_seeds(), and map::rotten_item_spawn().

◆ is_sided()

bool item::is_sided ( ) const

Returns true if item is armor and can be worn on different sides of the body.

Definition at line 806 of file item.cpp.

807{
808 const islot_armor *t = find_armor_data();
809 return t ? t->sided : false;
810}

References find_armor_data(), and islot_armor::sided.

Referenced by armor_fit_info(), armor_info(), Character::can_wear(), on_takeoff(), on_wear(), examine_item_menu::rate_action_change_side(), and set_side().

◆ is_silent()

bool item::is_silent ( ) const

Whether this is a (nearly) silent gun (a tiny bit of sound is allowed).

Non-guns are always silent.

Definition at line 6568 of file item.cpp.

6569{
6570 return gun_noise().volume < 5;
6571}
sound_data gun_noise(bool burst=false) const
Returns the sound of the gun being fired.
Definition: ranged.cpp:1813
int volume
Volume of the sound.
Definition: item.h:1860

References gun_noise(), and item::sound_data::volume.

Referenced by npc::check_or_use_weapon_cbm(), and npc::method_of_attack().

◆ is_soft()

bool item::is_soft ( ) const

Is this item flexible enough to be worn on body parts like antlers?

Definition at line 9852 of file item.cpp.

9853{
9854 const std::vector<material_id> mats = made_of();
9855 return std::any_of( mats.begin(), mats.end(), []( const material_id & mid ) {
9856 return mid.obj().soft();
9857 } );
9858}

References made_of().

Referenced by mutation_branch::conflicts_with_item(), and game_menus::inv::multiwash().

◆ is_tainted()

bool item::is_tainted ( ) const

Is item derived from a zombie?

Definition at line 9847 of file item.cpp.

9848{
9849 return corpse && corpse->has_flag( MF_POISON );
9850}
@ MF_POISON
Definition: mtype.h:80

References corpse, mtype::has_flag(), and MF_POISON.

Referenced by food_info().

◆ is_tool()

◆ is_toolmod()

bool item::is_toolmod ( ) const

Definition at line 6791 of file item.cpp.

6792{
6793 return !is_gunmod() && type->mod;
6794}

References is_gunmod(), itype::mod, and type.

Referenced by allow_crafting_component(), item_action_generator::map_actions_to_items(), iuse::multicooker(), and iuse::toolmod_attach().

◆ is_transformable()

bool item::is_transformable ( ) const

Definition at line 6989 of file item.cpp.

6990{
6991 return type->use_methods.find( "transform" ) != type->use_methods.end();
6992}

References type, and itype::use_methods.

Referenced by map::add_item().

◆ is_two_handed()

bool item::is_two_handed ( const Character guy) const

Whether the character needs both hands to wield this item.

Strength determines which weapons can be wielded with one hand

Definition at line 6430 of file item.cpp.

6431{
6432 if( has_flag( flag_ALWAYS_TWOHAND ) ) {
6433 return true;
6434 }
6435 ///\EFFECT_STR determines which weapons can be wielded with one hand
6436 return ( ( weight() / 113_gram ) > guy.str_cur * 4 );
6437}
int str_cur
Definition: character.h:264
static const std::string flag_ALWAYS_TWOHAND("ALWAYS_TWOHAND")

References flag_ALWAYS_TWOHAND(), has_flag(), Character::str_cur, and weight().

Referenced by Character::can_wear(), Character::can_wield(), ranged::gunmode_checks_common(), hardcoded_mutation_attack(), Character::item_handling_cost(), and Character::melee_special_effects().

◆ is_unarmed_weapon()

bool item::is_unarmed_weapon ( ) const

Definition at line 742 of file item.cpp.

743{
744 return has_flag( flag_UNARMED_WEAPON ) || is_null();
745}
static const std::string flag_UNARMED_WEAPON("UNARMED_WEAPON")

References flag_UNARMED_WEAPON(), has_flag(), and is_null().

Referenced by Character::crit_chance(), melee_train(), Character::roll_bash_damage(), Character::roll_cut_damage(), and Character::roll_stab_damage().

◆ is_upgrade()

bool item::is_upgrade ( ) const

Whether the CBM is an upgrade to another bionic module.

Definition at line 10066 of file item.cpp.

10067{
10068 if( !type->bionic ) {
10069 return false;
10070 }
10071 return type->bionic->is_upgrade;
10072}

References itype::bionic, and type.

Referenced by bionic_install_preset::get_denial(), and bionic_install_surgeon_preset::get_denial().

◆ is_watertight_container()

bool item::is_watertight_container ( ) const

◆ is_wheel()

bool item::is_wheel ( ) const

Definition at line 6781 of file item.cpp.

6782{
6783 return !!type->wheel;
6784}
cata::value_ptr< islot_wheel > wheel
Definition: itype.h:828

References type, and itype::wheel.

Referenced by can_do_activity_there(), tname(), wheel_area(), vehicle_part::wheel_diameter(), and vehicle_part::wheel_width().

◆ is_worn_only_with()

bool item::is_worn_only_with ( const item it) const

Returns true whether this item can be worn only when.

Parameters
itis worn.

Definition at line 839 of file item.cpp.

840{
843}

References flag_POWERARMOR_EXO(), flag_POWERARMOR_EXTERNAL(), flag_POWERARMOR_MOD(), and has_flag().

Referenced by Character::get_dependent_worn_items(), and pickup::reorder_for_dropping().

◆ item_has_uses_recursive()

bool item::item_has_uses_recursive ( ) const

Definition at line 80 of file item_action.cpp.

81{
82 if( !type->use_methods.empty() ) {
83 return true;
84 }
85
87}
bool item_has_uses_recursive() const
Definition: item_action.cpp:89

References contents, item_contents::item_has_uses_recursive(), type, and itype::use_methods.

◆ label()

std::string item::label ( unsigned int  quantity = 0) const

Returns label from "item_label" itemvar and quantity.

Definition at line 9982 of file item.cpp.

9983{
9984 if( has_label() ) {
9985 return get_var( "item_label" );
9986 }
9987
9988 return type_name( quantity );
9989}
std::string type_name(unsigned int quantity=1) const
Name of the item type (not the item), with proper plural.
Definition: item.cpp:9881
bool has_label() const
Returns true if item has "item_label" itemvar.
Definition: item.cpp:9977

References get_var(), has_label(), and type_name().

Referenced by tname().

◆ legacy_fast_forward_time()

void item::legacy_fast_forward_time ( )

Definition at line 10045 of file item.cpp.

10046{
10047 const time_duration tmp_bday = ( bday - calendar::turn_zero ) * 6;
10048 bday = calendar::turn_zero + tmp_bday;
10049
10050 rot *= 6;
10051
10052 const time_duration tmp_rot = ( last_rot_check - calendar::turn_zero ) * 6;
10054}

References bday, last_rot_check, and calendar::turn_zero.

Referenced by deserialize(), and submap::load().

◆ lift_strength()

int item::lift_strength ( ) const

Required strength to be able to successfully lift the item unaided by equipment.

Definition at line 5201 of file item.cpp.

5202{
5203 const int mass = units::to_gram( weight() );
5204 return std::max( mass / 10000, 1 );
5205}
constexpr value_type to_gram(const quantity< value_type, mass_in_milligram_tag > &v)
Definition: units_mass.h:68
quantity< std::int64_t, mass_in_milligram_tag > mass
Definition: units_mass.h:23

References units::to_gram(), and weight().

Referenced by can_do_activity_there(), veh_interact::can_remove_part(), and veh_interact::update_part_requirements().

◆ made_of() [1/3]

const std::vector< material_id > & item::made_of ( ) const

The ids of all the materials this is made of.

This may return an empty vector. The returned vector does not contain the null id.

Definition at line 6439 of file item.cpp.

6440{
6441 if( is_corpse() ) {
6442 return corpse->mat;
6443 }
6444 return type->materials;
6445}
std::vector< material_id > materials
Definition: itype.h:893
std::vector< material_id > mat
Definition: mtype.h:254

References corpse, is_corpse(), mtype::mat, itype::materials, and type.

Referenced by activity_on_turn_move_loot(), map::add_item(), map::add_item_or_charges(), avatar_funcs::add_or_drop_with_msg(), iuse::blech(), iuse::blech_because_unclean(), vehicle_part::can_reload(), can_unload_liquid(), saw_stock_actor::can_use_on(), Character::can_wear(), Character::can_wield(), MonsterGenerator::check_monster_definitions(), color_in_inventory(), crafting::complete_disassemble(), compute_default_effective_vitamins(), contents_made_of(), map::create_burnproducts(), auto_pickup::rule_list::create_rule(), salvage_actor::cut_up(), iexamine::cvdmachine(), move_items_activity_actor::do_turn(), Character::drop_invalid_inventory(), drop_or_handle(), final_info(), character_funcs::find_ammo_helper(), iexamine::fvat_empty(), iexamine::fvat_full(), Character::get_acquirable_energy(), get_base_material(), pickup_inventory_preset::get_denial(), comestible_inventory_preset::get_denial(), liquid_handler::get_liquid_target(), get_random_material(), repair_item_actor::handle_components(), liquid_handler::handle_liquid(), Character::i_add_or_drop(), in_container(), is_salvageable(), is_soft(), inscribe_actor::item_inscription(), iexamine::keg(), made_of(), made_of_any(), made_of_types(), Character::melee_special_effects(), Item_modifier::modify(), advanced_inventory::move_all_items(), advanced_inventory::move_content(), move_item(), iuse::multicooker(), npc_pickup_from_stack(), on_drop(), only_made_of(), liquid_handler::perform_liquid_transfer(), pick_one_up(), price(), monster::process_turn(), mattack::pull_metal_weapon(), item_reload_option::qty(), advanced_inventory::query_charges(), reload(), simulate_burn(), smash(), map::spawn_an_item(), starting_inv(), ranged::throw_item(), tname(), try_fuel_fire(), avatar_funcs::unload_item(), npc::value(), volume(), and Character::warmth().

◆ made_of() [2/3]

bool item::made_of ( const material_id mat_ident) const

Check we are made of this material (e.g.

matches at least one in our set.)

Definition at line 6485 of file item.cpp.

6486{
6487 const std::vector<material_id> &materials = made_of();
6488 return std::find( materials.begin(), materials.end(), mat_ident ) != materials.end();
6489}

References detail::find(), and made_of().

◆ made_of() [3/3]

bool item::made_of ( phase_id  phase) const

Are we solid, liquid, gas, plasma?

Definition at line 6496 of file item.cpp.

6497{
6498 if( is_null() ) {
6499 return false;
6500 }
6501 return type->phase == phase;
6502}

References is_null(), itype::phase, and type.

◆ made_of_any()

bool item::made_of_any ( const std::set< material_id > &  mat_idents) const

Check we are made of at least one of a set (e.g.

true if at least one item of the passed in set matches any material).

Parameters
mat_identsSet of material ids.

Definition at line 6461 of file item.cpp.

6462{
6463 const std::vector<material_id> &mats = made_of();
6464 if( mats.empty() ) {
6465 return false;
6466 }
6467
6468 return std::any_of( mats.begin(), mats.end(), [&mat_idents]( const material_id & e ) {
6469 return mat_idents.count( e );
6470 } );
6471}

References made_of().

Referenced by Character::can_eat(), goes_bad(), repair_inventory_preset::is_shown(), inscribe_actor::item_inscription(), ranged::throw_item(), and Character::throw_range().

◆ made_of_types()

std::vector< const material_type * > item::made_of_types ( ) const

Same as made_of(), but returns the material_type directly.

Definition at line 6452 of file item.cpp.

6453{
6454 std::vector<const material_type *> material_types_composed_of;
6455 for( const material_id &mat_id : made_of() ) {
6456 material_types_composed_of.push_back( &mat_id.obj() );
6457 }
6458 return material_types_composed_of;
6459}

References made_of().

Referenced by acid_resist(), bash_resist(), basic_info(), bullet_resist(), chip_resistance(), conductive(), cut_resist(), fire_resist(), flammable(), reinforceable(), and wind_resist().

◆ magazine_compatible()

std::set< itype_id > item::magazine_compatible ( bool  conversion = true) const

Get compatible magazines (if any) for this item.

Parameters
conversionwhether to include the effect of any flags or mods which convert item's ammo type
Returns
magazine compatibility which is always empty if item has integral magazine
See also
item::magazine_integral

Definition at line 7714 of file item.cpp.

7715{
7716 std::set<itype_id> mags = {};
7717 // mods that define magazine_adaptor may override the items usual magazines
7718 const std::vector<const item *> &mods = is_gun() ? gunmods() : toolmods();
7719 for( const item *m : mods ) {
7720 if( !m->type->mod->magazine_adaptor.empty() ) {
7721 for( const ammotype &atype : ammo_types( conversion ) ) {
7722 if( m->type->mod->magazine_adaptor.count( atype ) ) {
7723 std::set<itype_id> magazines_for_atype = m->type->mod->magazine_adaptor.find( atype )->second;
7724 mags.insert( magazines_for_atype.begin(), magazines_for_atype.end() );
7725 }
7726 }
7727 return mags;
7728 }
7729 }
7730
7731 for( const ammotype &atype : ammo_types( conversion ) ) {
7732 if( type->magazines.count( atype ) ) {
7733 std::set<itype_id> magazines_for_atype = type->magazines.find( atype )->second;
7734 mags.insert( magazines_for_atype.begin(), magazines_for_atype.end() );
7735 }
7736 }
7737 return mags;
7738}

References ammo_types(), gunmods(), is_gun(), itype::magazines, toolmods(), and type.

Referenced by mdeath::broken(), color_in_inventory(), character_funcs::find_reloadables(), gun_info(), avatar_funcs::gunmod_add(), is_reloadable_helper(), and tool_info().

◆ magazine_current() [1/2]

item * item::magazine_current ( )

Currently loaded magazine (if any)

Returns
current magazine or nullptr if either no magazine loaded or item has integral magazine
See also
item::magazine_integral

Definition at line 7740 of file item.cpp.

7741{
7742 return contents.get_item_with(
7743 []( const item & it ) {
7744 return it.is_magazine();
7745 } );
7746}
item * get_item_with(const std::function< bool(const item &)> &filter)

References contents, item_contents::get_item_with(), and is_magazine().

Referenced by ammo_capacity(), ammo_consume(), ammo_data(), ammo_remaining(), ammo_set(), ammo_unset(), item_funcs::can_be_unloaded(), turret_data::can_unload(), common_ammo_default(), cycle_action(), iuse::foodperson(), iuse::hand_crank(), is_gunmod_compatible(), character_funcs::list_ammo(), magazine_current(), Item_modifier::modify(), reload(), character_funcs::select_ammo(), tool_info(), iuse::toolmod_attach(), avatar_funcs::unload_item(), volume(), and weight().

◆ magazine_current() [2/2]

const item * item::magazine_current ( ) const

Definition at line 7748 of file item.cpp.

7749{
7750 return const_cast<item *>( this )->magazine_current();
7751}

References magazine_current().

◆ magazine_default()

itype_id item::magazine_default ( bool  conversion = true) const

Get the default magazine type (if any) for the current effective ammo type.

Parameters
conversionwhether to include the effect of any flags or mods which convert item's ammo type
Returns
magazine type or "null" if item has integral magazine or no magazines for current ammo type

Definition at line 7693 of file item.cpp.

7694{
7695 if( !ammo_types( conversion ).empty() ) {
7696 if( conversion ) {
7697 for( const item *m : is_gun() ? gunmods() : toolmods() ) {
7698 if( !m->type->mod->magazine_adaptor.empty() ) {
7699 auto mags = m->type->mod->magazine_adaptor.find( ammotype( *ammo_types( conversion ).begin() ) );
7700 if( mags != m->type->mod->magazine_adaptor.end() ) {
7701 return *( mags->second.begin() );
7702 }
7703 }
7704 }
7705 }
7706 auto mag = type->magazine_default.find( ammotype( *ammo_types( conversion ).begin() ) );
7707 if( mag != type->magazine_default.end() ) {
7708 return mag->second;
7709 }
7710 }
7711 return itype_id::NULL_ID();
7712}
std::map< ammotype, itype_id > magazine_default
Default magazine for each ammo type that can be used to reload this item.
Definition: itype.h:994

References ammo_types(), gunmods(), is_gun(), itype::magazine_default, itype::mod, string_id< itype >::NULL_ID(), toolmods(), and type.

Referenced by ammo_capacity(), ammo_set(), defense_game::caravan(), game::dump_stats(), and Item_modifier::modify().

◆ magazine_info()

void item::magazine_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 1885 of file item.cpp.

1887{
1888 if( !is_magazine() || has_flag( flag_NO_RELOAD ) ) {
1889 return;
1890 }
1891
1892 if( parts->test( iteminfo_parts::MAGAZINE_CAPACITY ) ) {
1893 for( const ammotype &at : ammo_types() ) {
1894 const std::string fmt = string_format( vgettext( "<num> round of %s",
1895 "<num> rounds of %s", ammo_capacity() ),
1896 at->name() );
1897 info.emplace_back( "MAGAZINE", _( "Capacity: " ), fmt, iteminfo::no_flags,
1898 ammo_capacity() );
1899 }
1900 }
1901 if( parts->test( iteminfo_parts::MAGAZINE_RELOAD ) ) {
1902 info.emplace_back( "MAGAZINE", _( "Reload time: " ), _( "<num> moves per round" ),
1903 iteminfo::lower_is_better, type->magazine->reload_time );
1904 }
1906}

References _, ammo_capacity(), ammo_types(), flag_NO_RELOAD(), has_flag(), info(), insert_separation_line(), is_magazine(), iteminfo::lower_is_better, itype::magazine, MAGAZINE_CAPACITY, MAGAZINE_RELOAD, iteminfo::no_flags, string_format(), iteminfo_query::test(), type, and vgettext().

Referenced by info().

◆ magazine_integral()

bool item::magazine_integral ( ) const

Does item have an integral magazine (as opposed to allowing detachable magazines)

Definition at line 7678 of file item.cpp.

7679{
7680 if( is_gun() && type->gun->clip > 0 ) {
7681 return true;
7682 }
7683 for( const item *m : is_gun() ? gunmods() : toolmods() ) {
7684 if( !m->type->mod->magazine_adaptor.empty() ) {
7685 return false;
7686 }
7687 }
7688
7689 // We have an integral magazine if we're a gun with an ammo capacity (clip) or we have no magazines.
7690 return ( is_gun() && type->gun->clip > 0 ) || type->magazines.empty();
7691}

References itype::gun, gunmods(), is_gun(), itype::magazines, toolmods(), and type.

Referenced by character_funcs::ammo_count_for(), ammo_set(), ammo_unset(), turret_data::can_reload(), defense_game::caravan(), color_in_inventory(), game::dump_stats(), character_funcs::fmt_wielded_weapon(), gun_info(), avatar_funcs::gunmod_add(), ideal_ranged_dps(), is_reloadable_helper(), item(), Item_modifier::modify(), price(), reload(), character_funcs::select_ammo(), tool_info(), wants_to_reload_with(), and weight().

◆ make_component_hash()

uint64_t item::make_component_hash ( ) const

Creates a hash from the itype_ids of this item's components.

Definition at line 8935 of file item.cpp.

8936{
8937 // First we need to sort the IDs so that identical ingredients give identical hashes.
8938 std::multiset<std::string> id_set;
8939 for( const item &it : components ) {
8940 id_set.insert( it.typeId().str() );
8941 }
8942
8943 std::string concatenated_ids;
8944 for( std::string id : id_set ) {
8945 concatenated_ids += id;
8946 }
8947
8948 std::hash<std::string> hasher;
8949 return hasher( concatenated_ids );
8950}

References components, base_camps::id, and string_id< T >::str().

Referenced by consumption_event::consumption_event(), and Character::fun_for().

◆ make_corpse()

item item::make_corpse ( const mtype_id mt = string_id<mtype>::NULL_ID(),
time_point  turn = calendar::turn,
const std::string &  name = "",
int  upgrade_time = -1 
)
static

Make a corpse of the given monster type.

The monster type id must be valid (see MonsterGenerator::get_all_mtypes).

The turn parameter sets the birthday of the corpse, in other words: the turn when the monster died. Because corpses are removed from the map when they reach a certain age, one has to be careful when placing corpses with a birthday of 0. They might be removed immediately when the map is loaded without been seen by the player.

The name parameter can be used to give the corpse item a name. This is used instead of the monster type name ("corpse of X" instead of "corpse of bear").

With the default parameters it makes a human corpse, created at the current turn.

Definition at line 511 of file item.cpp.

513{
514 if( !mt.is_valid() ) {
515 debugmsg( "tried to make a corpse with an invalid mtype id" );
516 }
517
518 std::string corpse_type = mt == mtype_id::NULL_ID() ? "corpse_generic_human" : "corpse";
519
520 item result( corpse_type, turn );
521 result.corpse = &mt.obj();
522
523 if( result.corpse->has_flag( MF_REVIVES ) ) {
524 if( one_in( 20 ) ) {
525 result.set_flag( "REVIVE_SPECIAL" );
526 }
527 result.set_var( "upgrade_time", std::to_string( upgrade_time ) );
528 }
529
530 // This is unconditional because the const itemructor above sets result.name to
531 // "human corpse".
532 result.corpse_name = name;
533
534 return result;
535}
std::string to_string(const time_duration &d)
Returns a string showing a duration.
Definition: calendar.cpp:327
bool one_in(int chance)
Definition: rng.cpp:65

References debugmsg, string_id< T >::is_valid(), MF_REVIVES, om_direction::name(), string_id< mtype >::NULL_ID(), string_id< T >::obj(), one_in(), to_string(), and calendar::turn.

Referenced by map::add_corpse(), game::catch_a_monster(), Single_item_creator::create_single(), map::draw_mine(), iuse::fish_trap(), basecamp::hunting_results(), make_mon_corpse(), MapExtras::mx_grave(), MapExtras::mx_mayhem(), MapExtras::mx_minefield(), Character::place_corpse(), rod_fish(), and mdeath::splatter().

◆ mark_as_used_by_player()

void item::mark_as_used_by_player ( const player p)

Marks the item as being used by this specific player, it remains unmarked for other players.

The player is identified by its id.

Definition at line 8883 of file item.cpp.

8884{
8885 std::string &used_by_ids = item_vars[ USED_BY_IDS ];
8886 if( used_by_ids.empty() ) {
8887 // *always* start with a ';'
8888 used_by_ids = ";";
8889 }
8890 // and always end with a ';'
8891 used_by_ids += string_format( "%d;", p.getID().get_value() );
8892}

References character_id::get_value(), Character::getID(), item_vars, string_format(), and USED_BY_IDS().

Referenced by reveal_map_actor::use().

◆ mark_chapter_as_read()

void item::mark_chapter_as_read ( const Character ch)

Mark one chapter of the book as read by the given player.

May do nothing if the book has no unread chapters. This is a per-character setting, see get_remaining_chapters.

Definition at line 7129 of file item.cpp.

7130{
7131 const std::string var = string_format( "remaining-chapters-%d", ch.getID().get_value() );
7132 if( type->book && type->book->chapters == 0 ) {
7133 // books without chapters will always have remaining chapters == 0, so we don't need to store them
7134 erase_var( var );
7135 return;
7136 }
7137 const int remain = std::max( 0, get_remaining_chapters( ch ) - 1 );
7138 set_var( var, remain );
7139}
void erase_var(const std::string &name)
Erase the value of the given variable.
Definition: item.cpp:1084

References itype::book, erase_var(), get_remaining_chapters(), character_id::get_value(), Character::getID(), set_var(), string_format(), and type.

Referenced by avatar::do_read(), and npc::finish_read().

◆ max_damage()

◆ med_info()

void item::med_info ( const item med_item,
std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 1645 of file item.cpp.

1647{
1648 const cata::value_ptr<islot_comestible> &med_com = med_item->get_comestible();
1649 if( med_com->quench != 0 && parts->test( iteminfo_parts::MED_QUENCH ) ) {
1650 info.push_back( iteminfo( "MED", _( "Quench: " ), med_com->quench ) );
1651 }
1652
1653 if( med_item->get_comestible_fun() != 0 && parts->test( iteminfo_parts::MED_JOY ) ) {
1654 info.push_back( iteminfo( "MED", _( "Enjoyability: " ),
1655 get_avatar().fun_for( *med_item ).first ) );
1656 }
1657
1658 if( med_com->stim != 0 && parts->test( iteminfo_parts::MED_STIMULATION ) ) {
1659 std::string name = string_format( "%s <stat>%s</stat>", _( "Stimulation:" ),
1660 med_com->stim > 0 ? _( "Upper" ) : _( "Downer" ) );
1661 info.push_back( iteminfo( "MED", name ) );
1662 }
1663
1664 if( parts->test( iteminfo_parts::MED_PORTIONS ) ) {
1665 info.push_back( iteminfo( "MED", _( "Portions: " ),
1666 std::abs( static_cast<int>( med_item->charges ) * batch ) ) );
1667 }
1668
1669 if( med_com->addict && parts->test( iteminfo_parts::DESCRIPTION_MED_ADDICTING ) ) {
1670 info.emplace_back( "DESCRIPTION", _( "* Consuming this item is <bad>addicting</bad>." ) );
1671 }
1672}
int get_comestible_fun() const
Definition: item.cpp:5508

References _, charges, DESCRIPTION_MED_ADDICTING, get_avatar(), get_comestible(), get_comestible_fun(), info(), MED_JOY, MED_PORTIONS, MED_QUENCH, MED_STIMULATION, om_direction::name(), string_format(), and iteminfo_query::test().

Referenced by info().

◆ melee_skill()

skill_id item::melee_skill ( ) const

The most relevant skill used with this melee weapon.

Can be "null" if this is not a weapon. Note this function returns null if the item is a gun for which you can use gun_skill() instead.

Definition at line 7221 of file item.cpp.

7222{
7223 if( !is_melee() ) {
7224 return skill_id::NULL_ID();
7225 }
7226
7227 if( has_flag( flag_UNARMED_WEAPON ) ) {
7228 return skill_unarmed;
7229 }
7230
7231 int hi = 0;
7233
7234 for( int idx = DT_NULL + 1; idx != NUM_DT; ++idx ) {
7235 const int val = damage_melee( static_cast<damage_type>( idx ) );
7236 const skill_id &sk = skill_by_dt( static_cast<damage_type>( idx ) );
7237 if( val > hi && sk ) {
7238 hi = val;
7239 res = sk;
7240 }
7241 }
7242
7243 return res;
7244}
const skill_id & skill_by_dt(damage_type dt)
Definition: damage.cpp:273
static const skill_id skill_unarmed("unarmed")

References damage_melee(), DT_NULL, flag_UNARMED_WEAPON(), has_flag(), is_melee(), string_id< Skill >::NULL_ID(), NUM_DT, skill_by_dt(), and skill_unarmed.

Referenced by contextualize_skill(), Character::crit_chance(), Character::get_hit_weapon(), Character::item_store_cost(), on_wield(), and character_funcs::try_wield_contents().

◆ merge_charges()

bool item::merge_charges ( const item rhs)

Merge charges of the other item into this item.

Returns
true if the items have been merged, otherwise false. Merging is only done for items counted by charges (count_by_charges) and items that stack together (stacks_with).

Definition at line 980 of file item.cpp.

981{
982 if( !count_by_charges() || !stacks_with( rhs ) ) {
983 return false;
984 }
985 // Prevent overflow when either item has "near infinite" charges.
986 if( charges >= INFINITE_CHARGES / 2 || rhs.charges >= INFINITE_CHARGES / 2 ) {
988 return true;
989 }
990 // We'll just hope that the item counter represents the same thing for both items
991 if( item_counter > 0 || rhs.item_counter > 0 ) {
992 item_counter = ( static_cast<double>( item_counter ) * charges + static_cast<double>
993 ( rhs.item_counter ) * rhs.charges ) / ( charges + rhs.charges );
994 }
995 charges += rhs.charges;
996 return true;
997}

References charges, count_by_charges(), INFINITE_CHARGES, item_counter, and stacks_with().

◆ min_damage()

int item::min_damage ( ) const

Minimum amount of damage to an item (state of maximum repair)

Definition at line 6237 of file item.cpp.

6238{
6239 return type->damage_min();
6240}
int damage_min() const
Definition: itype.cpp:46

References itype::damage_min(), and type.

Referenced by repair_item_actor::can_repair_target(), damage_color(), repair_item_actor::default_action(), iuse::gun_repair(), io(), mod_damage(), and set_damage().

◆ minimum_freshness_duration()

time_duration item::minimum_freshness_duration ( temperature_flag  temperature) const

Time that this item is guaranteed to stay fresh.

Parameters
temperatureTemperature flag used to cap the duration.
Returns
Remaining guaranteed freshness duration, assuming current storage conditions.

Definition at line 5726 of file item.cpp.

5727{
5729 unsigned long long rot_per_hour = get_hourly_rotpoints_at_temp( temperature_f );
5730
5731 if( rot_per_hour <= 0 || !type->comestible ) {
5733 }
5734
5735 time_duration remaining_rot = type->comestible->spoils - rot;
5736 // Has to be in int64 or it will overflow for long lasting food
5737 unsigned long long duration = to_turns<unsigned long long>( remaining_rot )
5738 * to_turns<unsigned long long>( 1_hours )
5739 / rot_per_hour;
5740 if( duration > to_turns<unsigned long long>( calendar::INDEFINITELY_LONG_DURATION ) ) {
5742 }
5743
5744 return time_duration::from_turns( static_cast<int>( duration ) );
5745}
static int temperature_flag_to_highest_temperature(temperature_flag temperature)
Definition: item.cpp:5708
const time_duration INDEFINITELY_LONG_DURATION
The expected duration of the cataclysm.

References itype::comestible, time_duration::from_turns(), get_hourly_rotpoints_at_temp(), calendar::INDEFINITELY_LONG_DURATION, rot, temperature_flag_to_highest_temperature(), and type.

Referenced by food_info().

◆ mitigate_damage()

void item::mitigate_damage ( damage_unit du) const

Assuming that specified du hit the armor, reduce du based on the item's resistance to the damage type.

This will never reduce du.amount below 0.

Definition at line 6389 of file item.cpp.

6390{
6391 const resistances res = resistances( *this );
6392 const float mitigation = res.get_effective_resist( du );
6393 du.amount -= mitigation;
6394 du.amount = std::max( 0.0f, du.amount );
6395}
float get_effective_resist(const damage_unit &du) const
Definition: damage.cpp:217

References damage_unit::amount, and resistances::get_effective_resist().

Referenced by Character::armor_absorb(), and character_funcs::is_bp_immune_to().

◆ mod_charges()

void item::mod_charges ( int  mod)

Modify the charges of this item, only use for items counted by charges! The item must have enough charges for this (>= quantity) and be counted by charges.

Parameters
modHow many charges should be removed.

Definition at line 9751 of file item.cpp.

9752{
9753 if( has_infinite_charges() ) {
9754 return;
9755 }
9756
9757 if( !count_by_charges() ) {
9758 debugmsg( "Tried to remove %s by charges, but item is not counted by charges.", tname() );
9759 } else if( mod < 0 && charges + mod < 0 ) {
9760 debugmsg( "Tried to remove charges that do not exist, removing maximum available charges instead." );
9761 charges = 0;
9762 } else if( mod > 0 && charges >= INFINITE_CHARGES - mod ) {
9763 charges = INFINITE_CHARGES - 1; // Highly unlikely, but finite charges should not become infinite.
9764 } else {
9765 charges += mod;
9766 }
9767}

References charges, count_by_charges(), debugmsg, has_infinite_charges(), INFINITE_CHARGES, and tname().

Referenced by throw_activity_actor::do_turn(), Character::eat(), fill_with(), player::reduce_charges(), and talk_effect_fun_t::set_u_buy_item().

◆ mod_damage() [1/2]

bool item::mod_damage ( int  qty)

same as other mod_damage, but uses DT_NULL as damage type.

Definition at line 6274 of file item.cpp.

6275{
6276 return mod_damage( qty, DT_NULL );
6277}

References DT_NULL, and mod_damage().

◆ mod_damage() [2/2]

bool item::mod_damage ( int  qty,
damage_type  dt 
)

Apply damage to const itemrained by min_damage and max_damage.

Parameters
qtymaximum amount by which to adjust damage (negative permissible)
dttype of damage which may be passed to on_damage callback
Returns
whether item should be destroyed

Definition at line 6252 of file item.cpp.

6253{
6254 bool destroy = false;
6255
6256 if( count_by_charges() ) {
6257 charges -= std::min( type->stack_size * qty / itype::damage_scale, charges );
6258 destroy |= charges == 0;
6259 }
6260
6261 if( qty > 0 ) {
6262 on_damage( qty, dt );
6263 }
6264
6265 if( !count_by_charges() ) {
6266 destroy |= damage_ + qty > max_damage();
6267
6268 damage_ = std::max( std::min( damage_ + qty, max_damage() ), min_damage() );
6269 }
6270
6271 return destroy;
6272}
void on_damage(int qty, damage_type dt)
Callback immediately before an item is damaged.
Definition: item.cpp:4568

References charges, count_by_charges(), damage_, itype::damage_scale, max_damage(), min_damage(), on_damage(), itype::stack_size, and type.

Referenced by Character::armor_absorb(), iuse::gun_repair(), inc_damage(), activity_handlers::make_zlave_finish(), mod_damage(), vehicle::mod_hp(), and repair_item_actor::repair().

◆ mod_energy()

units::energy item::mod_energy ( const units::energy qty)

Add or remove energy from a battery.

If adding the specified energy quantity would go over the battery's capacity fill the battery and ignore the remainder. If adding the specified energy quantity would reduce the battery's charge level below 0 do nothing and return how far below 0 it would have gone.

Parameters
qtyenergy quantity to add (can be negative)
Returns
0 valued energy quantity on success

Definition at line 576 of file item.cpp.

577{
578 if( !is_battery() ) {
579 debugmsg( "Tried to set energy of non-battery item" );
580 return 0_J;
581 }
582
583 units::energy val = energy_remaining() + qty;
584 if( val < 0_J ) {
585 return val;
586 } else if( val > type->battery->max_capacity ) {
587 energy = type->battery->max_capacity;
588 } else {
589 energy = val;
590 }
591 return 0_J;
592}

References itype::battery, debugmsg, energy, energy_remaining(), is_battery(), and type.

◆ mod_last_rot_check()

void item::mod_last_rot_check ( time_duration  processing_duration)

This is part of a workaround so that items don't rot away to nothing if the smoking rack is outside the reality bubble.

Parameters
processing_duration

Definition at line 5747 of file item.cpp.

5748{
5749 if( !has_own_flag( "PROCESSING" ) ) {
5750 debugmsg( "mod_last_rot_check called on non smoking item: %s", tname() );
5751 return;
5752 }
5753
5754 // Apply no rot while smoking
5755 last_rot_check += processing_duration;
5756}

References debugmsg, has_own_flag(), last_rot_check, and tname().

◆ mod_rot()

void item::mod_rot ( const time_duration val)
inline

Definition at line 863 of file item.h.

863 {
864 rot += val;
865 }

◆ mutations_from_wearing()

std::vector< trait_id > item::mutations_from_wearing ( const Character guy) const

Definition at line 9106 of file item.cpp.

9107{
9108 if( !is_relic() ) {
9109 return std::vector<trait_id> {};
9110 }
9111 std::vector<trait_id> muts;
9112
9113 for( const enchantment &ench : relic_data->get_enchantments() ) {
9114 for( const trait_id &mut : ench.get_mutations() ) {
9115 // this may not be perfectly accurate due to conditions
9116 muts.push_back( mut );
9117 }
9118 }
9119
9120 for( const trait_id &char_mut : guy.get_mutations() ) {
9121 for( auto iter = muts.begin(); iter != muts.end(); ) {
9122 if( char_mut == *iter ) {
9123 iter = muts.erase( iter );
9124 } else {
9125 ++iter;
9126 }
9127 }
9128 }
9129
9130 return muts;
9131}
std::vector< trait_id > get_mutations(bool include_hidden=true) const
Get the idents of all traits/mutations.

References Character::get_mutations(), is_relic(), and relic_data.

Referenced by Character::on_item_takeoff(), and Character::on_item_wear().

◆ needs_processing()

bool item::needs_processing ( ) const

Whether the item should be processed (by calling process).

Definition at line 8952 of file item.cpp.

8953{
8956 is_artifact() || is_food();
8957}
bool needs_processing() const
Whether the item should be processed (by calling process).
Definition: item.cpp:8952
bool is_artifact() const
Definition: item.cpp:6994
static const std::string flag_ETHEREAL_ITEM("ETHEREAL_ITEM")

References active, contents, item_contents::empty(), flag_ETHEREAL_ITEM(), flag_RADIO_ACTIVATION(), item_contents::front(), has_flag(), is_artifact(), is_container(), is_food(), and needs_processing().

Referenced by map::add_item(), vehicle::add_item(), submap::load(), map::make_active(), vehicle::make_active(), needs_processing(), liquid_handler::perform_liquid_transfer(), and Character::process_items().

◆ nname()

std::string item::nname ( const itype_id id,
unsigned int  quantity = 1 
)
static

Returns the translated item name for the item with given id.

The name is in the proper plural form as specified by the quantity parameter. This is roughly equivalent to creating an item instance and calling tname, however this function does not include strings like "(fresh)".

Definition at line 9952 of file item.cpp.

9953{
9954 return id->nname( quantity );
9955}

Referenced by act_vehicle_unload_fuel(), ammo_info(), veh_interact::calc_overview(), camp_car_description(), crafting::can_disassemble(), Character::can_eat(), player::craft_consume_tools(), harvest_list::describe(), veh_interact::display_details(), draw_caravan_items(), spellcasting_callback::draw_spell_info(), farm_action(), activity_handlers::fertilize_plot_do_turn(), final_info(), iexamine::fvat_empty(), plot_options::get_descriptions(), iexamine::get_seed_entries(), plot_options::get_zone_name_suggestion(), repair_item_actor::handle_components(), ammobelt_actor::info(), iexamine::keg(), ma_style_callback::key(), lcmatch_any(), mill_load_food(), iuse::multicooker(), vpart_info::name(), comp_selection< CompType >::nname(), parse_tags(), peek_related_recipe(), activity_handlers::plant_seed_finish(), iexamine::portable_structure(), iexamine::pour_into_keg(), vehicle::print_fuel_indicator(), vehicle::print_part_list(), iexamine::quern_examine(), crafting::query_tool_selection(), avatar_action::reload(), activity_handlers::repair_item_finish(), recipe::result_name(), vehicle::select_engine(), player::select_item_component(), talk_effect_fun_t::set_u_sell_item(), character_funcs::siphon(), smoker_load_food(), iexamine::smoker_options(), vehicle::start_engine(), tname(), tool_comp::to_string(), iexamine::tree_maple(), iexamine::tree_maple_tapped(), try_consume(), unfold_vehicle_iuse::use(), consume_drug_iuse::use(), sew_advanced_actor::use(), and vehicle::use_washing_machine().

◆ on_contents_changed()

void item::on_contents_changed ( )

◆ on_damage()

void item::on_damage ( int  qty,
damage_type  dt 
)

Callback immediately before an item is damaged.

Parameters
qtymaximum damage that will be applied (constrained by max_damage)
dttype of damage (or DT_NULL)

Definition at line 4568 of file item.cpp.

4569{
4570 if( is_corpse() && qty + damage_ >= max_damage() ) {
4572 }
4573}

References damage_, flag_PULPED(), is_corpse(), max_damage(), and set_flag().

Referenced by mod_damage(), and set_damage().

◆ on_drop() [1/2]

bool item::on_drop ( const tripoint pos)

Invokes item type's itype::drop_action.

This function can change the item.

Parameters
posWhere is the item being placed. Note: the item isn't there yet.
Returns
true if the item was destroyed during placement.

Definition at line 10017 of file item.cpp.

10018{
10019 return on_drop( pos, get_map() );
10020}
bool on_drop(const tripoint &pos)
Invokes item type's itype::drop_action.
Definition: item.cpp:10017

References get_map(), and on_drop().

Referenced by map::add_item_or_charges(), and on_drop().

◆ on_drop() [2/2]

bool item::on_drop ( const tripoint pos,
map map 
)

Invokes item type's itype::drop_action.

This function can change the item.

Parameters
posWhere is the item being placed. Note: the item isn't there yet.
mapA map object associated with that position.
Returns
true if the item was destroyed during placement.

Definition at line 10022 of file item.cpp.

10023{
10024 // dropping liquids, even currently frozen ones, on the ground makes them
10025 // dirty
10026 if( made_of( LIQUID ) && !m.has_flag( flag_LIQUIDCONT, pos ) &&
10027 !has_own_flag( "DIRTY" ) ) {
10028 set_flag( "DIRTY" );
10029 }
10030 avatar &you = get_avatar();
10031 you.flag_encumbrance();
10032 return type->drop_action && type->drop_action.call( you, *this, false, pos );
10033}
void flag_encumbrance()
Flag encumbrance for updating.
Definition: character.cpp:1763
static const std::string flag_LIQUIDCONT("LIQUIDCONT")
use_function drop_action
Action to take BEFORE the item is placed on map.
Definition: itype.h:899
int call(player &, item &, bool, const tripoint &) const
Definition: iuse.cpp:9824

References use_function::call(), itype::drop_action, Character::flag_encumbrance(), flag_LIQUIDCONT(), get_avatar(), map::has_flag(), has_own_flag(), LIQUID, made_of(), set_flag(), and type.

◆ on_pickup()

void item::on_pickup ( Character p)

Callback when a player starts carrying the item.

The item is already in the inventory and is called from there. This is not called when the item is added to the inventory from worn vector or weapon slot. The item is considered already carried.

Definition at line 4537 of file item.cpp.

4538{
4539 // Fake characters are used to determine pickup weight and volume
4540 if( p.is_fake() ) {
4541 return;
4542 }
4543 avatar &you = get_avatar();
4544 // TODO: artifacts currently only work with the player character
4545 if( &p == &you && type->artifact ) {
4546 g->add_artifact_messages( type->artifact->effects_carried );
4547 }
4548 // if game is loaded - don't want ownership assigned during char creation
4549 if( you.getID().is_valid() ) {
4551 }
4552 if( is_bucket_nonempty() ) {
4554 }
4555
4556 p.flag_encumbrance();
4557}
virtual bool is_fake() const
Returns true for non-real Creatures used temporarily; i.e.
Definition: creature.cpp:998
bool is_valid() const
Definition: character_id.h:19
bool spill_contents(const tripoint &pos)
void handle_pickup_ownership(Character &c)
Definition: item.cpp:4497
bool is_bucket_nonempty() const
Definition: item.cpp:6771

References itype::artifact, contents, Character::flag_encumbrance(), g, get_avatar(), Character::getID(), handle_pickup_ownership(), is_bucket_nonempty(), Creature::is_fake(), character_id::is_valid(), Character::pos(), item_contents::spill_contents(), and type.

Referenced by Character::i_add().

◆ on_takeoff()

void item::on_takeoff ( Character p)

Callback when a character takes off an item.

The item is still in the worn items vector but will be removed immediately after the function returns

Definition at line 4416 of file item.cpp.

4417{
4418 p.on_item_takeoff( *this );
4419
4420 if( is_sided() ) {
4422 }
4423
4424 // if power armor, no power_draw and active, shut down.
4425 if( type->can_use( "set_transformed" ) && active ) {
4426 const set_transformed_iuse *actor = dynamic_cast<const set_transformed_iuse *>
4427 ( this->get_use( "set_transformed" )->get_actor_ptr() );
4428 if( actor == nullptr ) {
4429 debugmsg( "iuse_actor type descriptor and actual type mismatch" );
4430 return;
4431 }
4432 actor->bypass( *p.as_player(), *this, false, p.pos() );
4433 }
4434}
void on_item_takeoff(const item &it)
Called when an item is taken off.
Definition: character.cpp:9870
virtual player * as_player()
Definition: creature.h:122
bool set_side(side s)
Change the side on which the item is worn.
Definition: item.cpp:819
This is a iuse_transform used by items with transform dependencies.
Definition: iuse_actor.h:350
int bypass(player &p, item &it, bool t, const tripoint &pos) const
Hack: Bypasses normal checks to transform an item.
Definition: iuse_actor.cpp:986

References active, Creature::as_player(), BOTH, set_transformed_iuse::bypass(), itype::can_use(), debugmsg, use_function::get_actor_ptr(), get_use(), is_sided(), Character::on_item_takeoff(), Character::pos(), set_side(), and type.

Referenced by Character::absorb_hit(), Character::i_rem(), and starting_clothes().

◆ on_wear()

void item::on_wear ( Character p)

Callback when a character starts wearing the item.

The item is already in the worn items vector and is called from there.

Definition at line 4318 of file item.cpp.

4319{
4320 if( is_sided() && get_side() == side::BOTH ) {
4321 if( has_flag( flag_SPLINT ) ) {
4323 if( ( covers( bodypart_id( "leg_l" ) ) && p.is_limb_broken( bodypart_id( "leg_r" ) ) &&
4324 !p.worn_with_flag( flag_SPLINT, bodypart_id( "leg_r" ) ) ) ||
4325 ( covers( bodypart_id( "arm_l" ) ) && p.is_limb_broken( bodypart_id( "arm_r" ) ) &&
4326 !p.worn_with_flag( flag_SPLINT, bodypart_id( "arm_r" ) ) ) ) {
4328 }
4329 } else if( has_flag( flag_POWERARMOR_MOD ) ) {
4330 // for power armor mods, wear on side with least mods
4331 std::vector< std::pair< body_part, int > > mod_parts;
4332 body_part bp = num_bp;
4333 bodypart_str_id bpid;
4334 int lhs = 0;
4335 int rhs = 0;
4336 for( std::size_t i = 0; i < static_cast< body_part >( num_bp ) ; ++i ) {
4337 bp = static_cast< body_part >( i );
4338 if( get_covered_body_parts().test( bp ) ) {
4339 mod_parts.emplace_back( bp, 0 );
4340 }
4341 }
4342 for( auto &elem : p.worn ) {
4343 for( std::pair< body_part, int > &mod_part : mod_parts ) {
4344 bpid = convert_bp( mod_part.first );
4345 if( elem.get_covered_body_parts().test( mod_part.first ) &&
4346 elem.has_flag( flag_POWERARMOR_MOD ) ) {
4347 if( elem.is_sided() && elem.get_side() == bpid->part_side ) {
4348 mod_part.second++;
4349 continue;
4350 }
4351 mod_part.second++;
4352 }
4353 }
4354 }
4355 for( std::pair< body_part, int > &mod_part : mod_parts ) {
4356 bpid = convert_bp( mod_part.first );
4357 if( bpid->part_side == side::LEFT && mod_part.second > lhs ) {
4358 add_msg( _( "left" ) );
4359 lhs = mod_part.second;
4360 } else if( bpid->part_side == side::RIGHT && mod_part.second > rhs ) {
4361 add_msg( _( "right" ) );
4362 rhs = mod_part.second;
4363 }
4364 }
4365 set_side( ( lhs > rhs ) ? side::RIGHT : side::LEFT );
4366 } else {
4367 // for sided items wear the item on the side which results in least encumbrance
4368 int lhs = 0;
4369 int rhs = 0;
4371 const char_encumbrance_data left_enc = p.get_encumbrance( *this );
4372 for( const body_part bp : all_body_parts ) {
4373 lhs += left_enc.elems[bp].encumbrance;
4374 }
4375
4377 const char_encumbrance_data right_enc = p.get_encumbrance( *this );
4378 for( const body_part bp : all_body_parts ) {
4379 rhs += right_enc.elems[bp].encumbrance;
4380 }
4381
4382 set_side( lhs <= rhs ? side::LEFT : side::RIGHT );
4383 }
4384 }
4385
4386 if( type->can_use( "set_transformed" ) ) {
4387 bool transform = false;
4388 const set_transformed_iuse *actor = dynamic_cast<const set_transformed_iuse *>
4389 ( this->get_use( "set_transformed" )->get_actor_ptr() );
4390 if( actor == nullptr ) {
4391 debugmsg( "iuse_actor type descriptor and actual type mismatch" );
4392 return;
4393 }
4394 std::string transform_flag = actor->dependencies;
4395 for( const auto &elem : p.worn ) {
4396 if( elem.has_flag( transform_flag ) && elem.active != active ) {
4397 transform = true;
4398 }
4399 }
4400 if( transform && actor->restricted ) {
4401 actor->bypass( *p.as_player(), *this, false, p.pos() );
4402 }
4403 }
4404
4405 // TODO: artifacts currently only work with the player character
4406 if( &p == &get_avatar() && type->artifact ) {
4407 g->add_artifact_messages( type->artifact->effects_worn );
4408 }
4409 // if game is loaded - don't want ownership assigned during char creation
4410 if( get_avatar().getID().is_valid() ) {
4412 }
4413 p.on_item_wear( *this );
4414}
constexpr std::array< body_part, 12 > all_body_parts
Contains all valid body_part values in the order they are defined in.
Definition: bodypart.h:84
body_part
Definition: bodypart.h:41
@ num_bp
Definition: bodypart.h:54
bool worn_with_flag(const std::string &flag, const bodypart_id &bp=bodypart_str_id::NULL_ID()) const
Returns true if the player is wearing an item with the given flag.
Definition: character.cpp:3265
void on_item_wear(const item &it)
Called when an item is worn.
Definition: character.cpp:9855
bool is_limb_broken(const bodypart_id &limb) const
Returns true if the limb is broken.
Definition: character.cpp:1265
char_encumbrance_data get_encumbrance() const
Get encumbrance for all body parts.
Definition: character.cpp:3705
Just like the string_id, this is a wrapper for int based identifiers.
Definition: int_id.h:20
bool restricted
Whether the object can only be transformed externally.
Definition: iuse_actor.h:355
std::string dependencies
String defining flag needed on activating item.
Definition: iuse_actor.h:360
static const std::string flag_SPLINT("SPLINT")
void add_msg(std::string msg)
Definition: messages.cpp:910
side part_side
Definition: bodypart.h:128
std::array< encumbrance_data, num_bp > elems

References _, active, add_msg(), all_body_parts, itype::artifact, Creature::as_player(), BOTH, set_transformed_iuse::bypass(), itype::can_use(), convert_bp(), covers(), debugmsg, set_transformed_iuse::dependencies, char_encumbrance_data::elems, flag_POWERARMOR_MOD(), flag_SPLINT(), g, use_function::get_actor_ptr(), get_avatar(), get_covered_body_parts(), Character::get_encumbrance(), get_side(), get_use(), handle_pickup_ownership(), has_flag(), Character::is_limb_broken(), is_sided(), LEFT, num_bp, Character::on_item_wear(), body_part_type::part_side, Character::pos(), set_transformed_iuse::restricted, RIGHT, set_side(), body_part_set::test(), iexamine::transform(), type, Character::worn, and Character::worn_with_flag().

Referenced by starting_clothes().

◆ on_wield()

void item::on_wield ( player p,
int  mv = 0 
)

Callback when a player starts wielding the item.

The item is already in the weapon slot and is called from there.

Parameters
pplayer that has started wielding item
mvnumber of moves already spent wielding the weapon

Definition at line 4436 of file item.cpp.

4437{
4438 // TODO: artifacts currently only work with the player character
4439 if( &p == &get_avatar() && type->artifact ) {
4440 g->add_artifact_messages( type->artifact->effects_wielded );
4441 }
4442
4443 // weapons with bayonet/bipod or other generic "unhandiness"
4444 if( has_flag( flag_SLOW_WIELD ) && !is_gunmod() ) {
4445 float d = 32.0; // arbitrary linear scaling factor
4446 if( is_gun() ) {
4447 d /= std::max( p.get_skill_level( gun_skill() ), 1 );
4448 } else if( is_melee() ) {
4449 d /= std::max( p.get_skill_level( melee_skill() ), 1 );
4450 }
4451
4452 int penalty = get_var( "volume", volume() / units::legacy_volume_factor ) * d;
4453 p.moves -= penalty;
4454 mv += penalty;
4455 }
4456
4457 // firearms with a folding stock or tool/melee without collapse/retract iuse
4458 if( has_flag( flag_NEEDS_UNFOLD ) && !is_gunmod() ) {
4459 int penalty = 50; // 200-300 for guns, 50-150 for melee, 50 as fallback
4460 if( is_gun() ) {
4461 penalty = std::max( 0, 300 - p.get_skill_level( gun_skill() ) * 10 );
4462 } else if( is_melee() ) {
4463 penalty = std::max( 0, 150 - p.get_skill_level( melee_skill() ) * 10 );
4464 }
4465
4466 p.moves -= penalty;
4467 mv += penalty;
4468 }
4469
4470 std::string msg;
4471
4472 if( mv > 500 ) {
4473 msg = _( "It takes you an extremely long time to wield your %s." );
4474 } else if( mv > 250 ) {
4475 msg = _( "It takes you a very long time to wield your %s." );
4476 } else if( mv > 100 ) {
4477 msg = _( "It takes you a long time to wield your %s." );
4478 } else if( mv > 50 ) {
4479 msg = _( "It takes you several seconds to wield your %s." );
4480 } else {
4481 msg = _( "You wield your %s." );
4482 }
4483 // if game is loaded - don't want ownership assigned during char creation
4484 if( p.getID().is_valid() ) {
4486 }
4487 p.add_msg_if_player( m_neutral, msg, tname() );
4488
4489 if( !p.martial_arts_data->selected_is_none() ) {
4490 p.martial_arts_data->martialart_use_message( p );
4491 }
4492
4493 // Update encumbrance in case we were wearing it
4494 p.flag_encumbrance();
4495}
int moves
Definition: creature.h:582
void add_msg_if_player(const std::string &msg) const override
Definition: player.cpp:367
@ m_neutral
Definition: enums.h:267
static const std::string flag_NEEDS_UNFOLD("NEEDS_UNFOLD")
static const std::string flag_SLOW_WIELD("SLOW_WIELD")

References _, player::add_msg_if_player(), itype::artifact, Character::flag_encumbrance(), flag_NEEDS_UNFOLD(), flag_SLOW_WIELD(), g, get_avatar(), Character::get_skill_level(), get_var(), Character::getID(), gun_skill(), handle_pickup_ownership(), has_flag(), is_gun(), is_gunmod(), is_melee(), character_id::is_valid(), units::legacy_volume_factor, m_neutral, Character::martial_arts_data, melee_skill(), Creature::moves, tname(), type, and volume().

Referenced by character_funcs::try_wield_contents(), and avatar::wield().

◆ only_made_of()

bool item::only_made_of ( const std::set< material_id > &  mat_idents) const

Check we are made of only the materials (e.g.

false if we have one material not in the set or no materials at all).

Parameters
mat_identsSet of material ids.

Definition at line 6473 of file item.cpp.

6474{
6475 const std::vector<material_id> &mats = made_of();
6476 if( mats.empty() ) {
6477 return false;
6478 }
6479
6480 return std::all_of( mats.begin(), mats.end(), [&mat_idents]( const material_id & e ) {
6481 return mat_idents.count( e );
6482 } );
6483}

References made_of().

Referenced by salvage_actor::try_to_cut_up(), and salvage_actor::valid_to_cut_up().

◆ operator<()

bool item::operator< ( const item other) const

Definition at line 7183 of file item.cpp.

7184{
7185 const item_category &cat_a = get_category();
7186 const item_category &cat_b = other.get_category();
7187 if( cat_a != cat_b ) {
7188 return cat_a < cat_b;
7189 } else {
7190 const item *me = is_container() && !contents.empty() ? &contents.front() : this;
7191 const item *rhs = other.is_container() &&
7192 !other.contents.empty() ? &other.contents.front() : &other;
7193
7194 const itype *me_type = me->type;
7195 const itype *rhs_type = rhs->type;
7196 if( !me_type || !rhs_type ) {
7197 return !!me_type;
7198 }
7199
7200 if( me_type->get_id() == rhs_type->get_id() ) {
7201 if( me->is_money() ) {
7202 return me->charges > rhs->charges;
7203 }
7204 return me->charges < rhs->charges;
7205 } else {
7206 std::string n1 = me_type->nname( 1 );
7207 std::string n2 = rhs_type->nname( 1 );
7208 return localized_compare( n1, n2 );
7209 }
7210 }
7211}

References charges, contents, item_contents::empty(), item_contents::front(), get_category(), itype::get_id(), is_container(), is_money(), localized_compare, itype::nname(), other, and type.

◆ operator<=()

bool item::operator<= ( const item other) const
inline

LUA: We need this operator defined for Lua bindings to compile.

Definition at line 1262 of file item.h.

1262 {
1263 return operator<( other ) || operator==( other );
1264 }
bool operator==(const item &rhs) const
LUA: We need this operator defined for Lua bindings to compile.
Definition: item.h:1258
bool operator<(const item &other) const
Definition: item.cpp:7183

References operator<(), coords::operator==(), and other.

◆ operator=() [1/2]

item & item::operator= ( const item )
default

◆ operator=() [2/2]

item & item::operator= ( item &&  )
default

◆ operator==()

bool item::operator== ( const item rhs) const
inline

LUA: We need this operator defined for Lua bindings to compile.

Definition at line 1258 of file item.h.

1258 {
1259 return this == &rhs;
1260 };

◆ price()

int item::price ( bool  practical) const

Returns the monetary value of an item.

If practical is false, returns pre-cataclysm market value, otherwise returns approximate post-cataclysm value.

Definition at line 4947 of file item.cpp.

4948{
4949 int res = 0;
4950
4951 visit_items( [&res, practical]( const item * e ) {
4952 if( e->rotten() ) {
4953 // TODO: Special case things that stay useful when rotten
4954 return VisitResponse::NEXT;
4955 }
4956
4957 int child = units::to_cent( practical ? e->type->price_post : e->type->price );
4958 if( e->damage() > 0 ) {
4959 // maximal damage level is 4, maximal reduction is 40% of the value.
4960 child -= child * static_cast<double>( e->damage_level( 4 ) ) / 10;
4961 }
4962
4963 if( e->count_by_charges() || e->made_of( LIQUID ) ) {
4964 // price from json data is for default-sized stack
4965 child *= e->charges / static_cast<double>( e->type->stack_size );
4966
4967 } else if( e->magazine_integral() && e->ammo_remaining() && e->ammo_data() ) {
4968 // items with integral magazines may contain ammunition which can affect the price
4969 child += item( e->ammo_data(), calendar::turn, e->charges ).price( practical );
4970
4971 } else if( e->is_tool() && e->ammo_types().empty() && e->ammo_capacity() ) {
4972 // if tool has no ammo (e.g. spray can) reduce price proportional to remaining charges
4973 child *= e->ammo_remaining() / static_cast<double>( std::max( e->type->charges_default(), 1 ) );
4974 }
4975
4976 res += child;
4977 return VisitResponse::NEXT;
4978 } );
4979
4980 return res;
4981}
constexpr value_type to_cent(const quantity< value_type, money_in_cent_tag > &v)
Definition: units_money.h:44
units::money price
Value before cataclysm.
Definition: itype.h:956
units::money price_post
Value after cataclysm, dependent upon practical usages.
Definition: itype.h:958

References ammo_capacity(), ammo_data(), ammo_remaining(), ammo_types(), count_by_charges(), damage(), is_tool(), LIQUID, made_of(), magazine_integral(), NEXT, itype::price, itype::price_post, rotten(), units::to_cent(), type, and visitable< item >::visit_items().

Referenced by talk_function::bionic_install(), talk_function::bionic_remove(), defense_game::caravan(), draw_caravan_items(), talk_function::field_harvest(), final_info(), bionic_install_surgeon_preset::get_money_amount(), npc_trading::init_buying(), npc_trading::init_selling(), parse_tags(), talk_effect_fun_t::set_bulk_trade_accept(), npc::shop_restock(), npc::value(), npc::wants_to_buy(), and npc::wants_to_sell().

◆ process() [1/2]

bool item::process ( player carrier,
const tripoint pos,
bool  activate,
temperature_flag  flag,
const weather_manager weather_generator 
)

Definition at line 9627 of file item.cpp.

9629{
9630 const bool preserves = type->container && type->container->preserves;
9631 const bool seals = type->container && type->container->seals;
9632 std::vector<item *> removed_items;
9633 visit_items( [&]( item * it ) {
9634 if( preserves ) {
9635 // Simulate that the item has already "rotten" up to last_rot_check, but as item::rot
9636 // is not changed, the item is still fresh.
9638 }
9639 if( it->process_internal( carrier, pos, activate, seals, flag, weather_generator ) ) {
9640 removed_items.push_back( it );
9641 }
9642 return VisitResponse::NEXT;
9643 } );
9644 for( item *it : removed_items ) {
9645 if( it != this ) {
9646 remove_item( *it );
9647 }
9648 }
9649 return !removed_items.empty() && std::any_of( removed_items.begin(), removed_items.end(),
9650 [this]( const item * r ) {
9651 return r == this;
9652 } );
9653}
bool process_internal(player *carrier, const tripoint &pos, bool activate, bool seals, temperature_flag flag, const weather_manager &weather_generator)
Definition: item.cpp:9655
item & activate()
Filter converting instance to active state.
Definition: item.cpp:561

References activate(), itype::container, last_rot_check, NEXT, process_internal(), visitable< item >::remove_item(), calendar::turn, type, and visitable< item >::visit_items().

◆ process() [2/2]

bool item::process ( player carrier,
const tripoint pos,
bool  activate,
temperature_flag  flag = temperature_flag::TEMP_NORMAL 
)

This is called once each turn.

It's usually only useful for active items, but can be called for inactive items without problems. It is recursive, and calls process on any contained items.

Parameters
carrierThe player / npc that carries the item. This can be null when the item is not carried by anyone (laying on ground)!
posThe location of the item on the map, same system as player::pos used. If the item is carried, it should be the location of the carrier.
activateWhether the item should be activated (true), or processed as an active item.
Returns
true if the item has been destroyed by the processing. The caller should than delete the item wherever it was stored. Returns false if the item is not destroyed.

Definition at line 9621 of file item.cpp.

9623{
9624 return process( carrier, pos, activate, flag, get_weather() );
9625}
bool process(player *carrier, const tripoint &pos, bool activate, temperature_flag flag=temperature_flag::TEMP_NORMAL)
This is called once each turn.
Definition: item.cpp:9621
weather_manager & get_weather()
Definition: weather.cpp:64

References activate(), get_weather(), and process().

Referenced by map::add_item(), iuse::cable_attach(), drop_or_embed_projectile(), mattack::kamikaze(), process(), vehicle_part::process_contents(), Character::process_items(), and iuse::tow_attach().

◆ process_artifact()

void item::process_artifact ( player carrier,
const tripoint pos 
)

Process and apply artifact effects.

This should be called exactly once each turn, it may modify character stats (like speed, strength, ...), so call it after those have been reset.

Parameters
carrierThe character carrying the artifact, can be null.
posThe location of the artifact (should be the player location if carried).

Definition at line 9091 of file item.cpp.

9092{
9093 if( !is_artifact() ) {
9094 return;
9095 }
9096 // Artifacts are currently only useful for the player character, the messages
9097 // don't consider npcs. Also they are not processed when laying on the ground.
9098 // TODO: change game::process_artifact to work with npcs,
9099 // TODO: consider moving game::process_artifact here.
9100 if( carrier == &get_avatar() ) {
9101 g->process_artifact( *this, *carrier );
9102 }
9103}

References g, get_avatar(), and is_artifact().

Referenced by Character::process_turn().

◆ process_blackpowder_fouling()

bool item::process_blackpowder_fouling ( player carrier)
protected

Definition at line 9610 of file item.cpp.

9611{
9612 if( damage() < max_damage() && one_in( 2000 ) ) {
9614 if( carrier ) {
9615 carrier->add_msg_if_player( m_bad, _( "Your %s rusts due to blackpowder fouling." ), tname() );
9616 }
9617 }
9618 return false;
9619}
@ m_bad
Definition: enums.h:261

References _, player::add_msg_if_player(), damage(), DT_ACID, inc_damage(), m_bad, max_damage(), one_in(), and tname().

Referenced by process_internal().

◆ process_cable()

bool item::process_cable ( player carrier,
const tripoint pos 
)
protected

Definition at line 9392 of file item.cpp.

9393{
9394 if( carrier == nullptr ) {
9395 //reset_cable( carrier );
9396 return false;
9397 }
9398 std::string state = get_var( "state" );
9399 if( state == "solar_pack_link" || state == "solar_pack" ) {
9400 if( !carrier->has_item( *this ) || !carrier->worn_with_flag( "SOLARPACK_ON" ) ) {
9401 carrier->add_msg_if_player( m_bad, _( "You notice the cable has come loose!" ) );
9402 reset_cable( carrier );
9403 return false;
9404 }
9405 }
9406
9407 static const item_filter used_ups = [&]( const item & itm ) {
9408 return itm.get_var( "cable" ) == "plugged_in";
9409 };
9410
9411 if( state == "UPS" ) {
9412 if( !carrier->has_item( *this ) || !carrier->has_item_with( used_ups ) ) {
9413 carrier->add_msg_if_player( m_bad, _( "You notice the cable has come loose!" ) );
9414 for( item *used : carrier->items_with( used_ups ) ) {
9415 used->erase_var( "cable" );
9416 }
9417 reset_cable( carrier );
9418 return false;
9419 }
9420 }
9421 const std::optional<tripoint> source = get_cable_target( carrier, pos );
9422 if( !source ) {
9423 return false;
9424 }
9425 map &here = get_map();
9426 if( !here.veh_at( *source ) || ( source->z != g->get_levz() && !here.has_zlevels() ) ) {
9427 if( carrier->has_item( *this ) ) {
9428 carrier->add_msg_if_player( m_bad, _( "You notice the cable has come loose!" ) );
9429 }
9430 reset_cable( carrier );
9431 return false;
9432 }
9433
9434 int distance = rl_dist( pos, *source );
9435 int max_charges = type->maximum_charges();
9436 charges = max_charges - distance;
9437
9438 if( charges < 1 ) {
9439 if( carrier->has_item( *this ) ) {
9440 carrier->add_msg_if_player( m_bad, _( "The over-extended cable breaks loose!" ) );
9441 }
9442 reset_cable( carrier );
9443 }
9444
9445 return false;
9446}
void reset_cable(player *p)
Helper to bring a cable back to its initial state.
Definition: item.cpp:9448
std::optional< tripoint > get_cable_target(Character *p, const tripoint &pos) const
Gets the point (vehicle tile) the cable is connected to.
Definition: item.cpp:9372
std::vector< item * > items_with(const std::function< bool(const item &)> &filter)
Returns all items (including those within a container) matching the filter.
Definition: visitable.cpp:325
std::function< bool(const item &)> item_filter
Definition: game.h:119
int maximum_charges() const
Definition: itype.cpp:123

References _, player::add_msg_if_player(), charges, g, get_cable_target(), get_map(), get_var(), visitable< T >::has_item(), visitable< T >::has_item_with(), anonymous_namespace{iexamine_elevator.cpp}::elevator::here(), visitable< T >::items_with(), m_bad, itype::maximum_charges(), reset_cable(), rl_dist(), type, and Character::worn_with_flag().

Referenced by process_internal().

◆ process_corpse()

bool item::process_corpse ( player carrier,
const tripoint pos 
)
protected

Definition at line 9149 of file item.cpp.

9150{
9151 // some corpses rez over time
9152 if( corpse == nullptr || damage() >= max_damage() ) {
9153 return false;
9154 }
9155 if( corpse->zombify_into && rotten() ) {
9156 rot -= get_shelf_life();
9158 return false;
9159 }
9160 if( !ready_to_revive( pos ) ) {
9161 return false;
9162 }
9163 if( rng( 0, volume() / units::legacy_volume_factor ) > burnt && g->revive_corpse( pos, *this ) ) {
9164 if( carrier == nullptr ) {
9165 if( get_avatar().sees( pos ) ) {
9166 if( corpse->in_species( ROBOT ) ) {
9167 add_msg( m_warning, _( "A nearby robot has repaired itself and stands up!" ) );
9168 } else {
9169 add_msg( m_warning, _( "A nearby corpse rises and moves towards you!" ) );
9170 }
9171 }
9172 } else {
9173 if( corpse->in_species( ROBOT ) ) {
9174 carrier->add_msg_if_player( m_warning,
9175 _( "Oh dear god, a robot you're carrying has started moving!" ) );
9176 } else {
9177 carrier->add_msg_if_player( m_warning,
9178 _( "Oh dear god, a corpse you're carrying has started moving!" ) );
9179 }
9180 }
9181 // Destroy this corpse item
9182 return true;
9183 }
9184
9185 return false;
9186}
bool ready_to_revive(const tripoint &pos) const
Whether this corpse should revive now.
Definition: item.cpp:5991
@ m_warning
Definition: enums.h:264
static const species_id ROBOT("ROBOT")
mtype_id zombify_into
Definition: mtype.h:332
bool in_species(const species_id &spec) const
Definition: mtype.cpp:122

References _, add_msg(), player::add_msg_if_player(), burnt, corpse, damage(), g, get_avatar(), get_shelf_life(), mtype::in_species(), units::legacy_volume_factor, m_warning, max_damage(), ready_to_revive(), rng(), ROBOT, rotten(), volume(), and mtype::zombify_into.

Referenced by process_internal().

◆ process_extinguish()

bool item::process_extinguish ( player carrier,
const tripoint pos 
)
protected

Definition at line 9297 of file item.cpp.

9298{
9299 // checks for water
9300 bool extinguish = false;
9301 bool in_inv = carrier != nullptr && carrier->has_item( *this );
9302 bool submerged = false;
9303 bool precipitation = false;
9304 bool windtoostrong = false;
9305 bool in_veh = carrier != nullptr && carrier->in_vehicle;
9306 int windpower = get_weather().windspeed;
9307 switch( get_weather().weather_id->precip ) {
9309 precipitation = one_in( 100 );
9310 break;
9312 precipitation = one_in( 50 );
9313 break;
9315 precipitation = one_in( 10 );
9316 break;
9317 default:
9318 break;
9319 }
9320 map &here = get_map();
9321 if( in_inv && !in_veh && here.has_flag( flag_DEEP_WATER, pos ) ) {
9322 extinguish = true;
9323 submerged = true;
9324 }
9325 if( ( !in_inv && here.has_flag( flag_LIQUID, pos ) && !here.veh_at( pos ) ) ||
9326 ( precipitation && !g->is_sheltered( pos ) ) ) {
9327 extinguish = true;
9328 }
9329 if( in_inv && windpower > 5 && !g->is_sheltered( pos ) &&
9330 this->has_flag( flag_WIND_EXTINGUISH ) ) {
9331 windtoostrong = true;
9332 extinguish = true;
9333 }
9334 if( !extinguish ||
9335 ( in_inv && precipitation && carrier->primary_weapon().has_flag( flag_RAIN_PROTECT ) ) ) {
9336 return false; //nothing happens
9337 }
9338 if( carrier != nullptr ) {
9339 if( submerged ) {
9340 carrier->add_msg_if_player( m_neutral, _( "Your %s is quenched by water." ), tname() );
9341 } else if( precipitation ) {
9342 carrier->add_msg_if_player( m_neutral, _( "Your %s is quenched by precipitation." ),
9343 tname() );
9344 } else if( windtoostrong ) {
9345 carrier->add_msg_if_player( m_neutral, _( "Your %s is blown out by the wind." ),
9346 tname() );
9347 }
9348 }
9349
9350 // cig dies out
9351 if( has_flag( flag_LITCIG ) ) {
9352 if( typeId() == itype_cig_lit ) {
9354 } else if( typeId() == itype_cigar_lit ) {
9356 } else { // joint
9358 }
9359 } else { // transform (lit) items
9360 if( type->tool->revert_to ) {
9361 convert( *type->tool->revert_to );
9362 } else {
9363 type->invoke( carrier != nullptr ? *carrier : get_avatar(), *this, pos, "transform" );
9364 }
9365
9366 }
9367 active = false;
9368 // Item remains
9369 return false;
9370}
bool in_vehicle
Definition: character.h:1573
item & primary_weapon()
Legacy code hack, don't use.
Definition: melee.cpp:167
static const itype_id itype_cigar_butt("cigar_butt")
static const itype_id itype_joint_roach("joint_roach")
static const itype_id itype_cig_butt("cig_butt")
static const std::string flag_LIQUID("LIQUID")
static const std::string flag_DEEP_WATER("DEEP_WATER")
static const itype_id itype_cigar_lit("cigar_lit")
static const std::string flag_WIND_EXTINGUISH("WIND_EXTINGUISH")
static const std::string flag_RAIN_PROTECT("RAIN_PROTECT")
static const itype_id itype_cig_lit("cig_lit")
int invoke(player &p, item &it, const tripoint &pos) const
Definition: itype.cpp:180

References _, active, player::add_msg_if_player(), convert(), flag_DEEP_WATER(), flag_LIQUID(), flag_LITCIG(), flag_RAIN_PROTECT(), flag_WIND_EXTINGUISH(), g, get_avatar(), get_map(), get_weather(), has_flag(), visitable< T >::has_item(), heavy, anonymous_namespace{iexamine_elevator.cpp}::elevator::here(), Character::in_vehicle, itype::invoke(), itype_cig_butt, itype_cig_lit, itype_cigar_butt, itype_cigar_lit, itype_joint_roach, light, m_neutral, one_in(), Character::primary_weapon(), tname(), itype::tool, type, typeId(), very_light, and weather_manager::windspeed.

Referenced by process_internal(), and process_litcig().

◆ process_fake_mill()

bool item::process_fake_mill ( player carrier,
const tripoint pos 
)
protected

Definition at line 9188 of file item.cpp.

9189{
9190 map &here = get_map();
9191 if( here.furn( pos ) != furn_str_id( "f_wind_mill_active" ) &&
9192 here.furn( pos ) != furn_str_id( "f_water_mill_active" ) ) {
9193 item_counter = 0;
9194 return true; //destroy fake mill
9195 }
9196 if( age() >= 6_hours || item_counter == 0 ) {
9198 birthday() ); //activate effects when timers goes to zero
9199 return true; //destroy fake mill item
9200 }
9201
9202 return false;
9203}
void mill_finalize(player &, const tripoint &examp, const time_point &start_time)
Definition: iexamine.cpp:5412

References age(), birthday(), get_avatar(), get_map(), anonymous_namespace{iexamine_elevator.cpp}::elevator::here(), item_counter, and iexamine::mill_finalize().

Referenced by process_internal().

◆ process_fake_smoke()

bool item::process_fake_smoke ( player carrier,
const tripoint pos 
)
protected

Definition at line 9205 of file item.cpp.

9206{
9207 map &here = get_map();
9208 if( here.furn( pos ) != furn_str_id( "f_smoking_rack_active" ) &&
9209 here.furn( pos ) != furn_str_id( "f_metal_smoking_rack_active" ) ) {
9210 item_counter = 0;
9211 return true; //destroy fake smoke
9212 }
9213
9214 if( age() >= 6_hours || item_counter == 0 ) {
9215 iexamine::on_smoke_out( pos, birthday() ); //activate effects when timers goes to zero
9216 return true; //destroy fake smoke when it 'burns out'
9217 }
9218
9219 return false;
9220}
void on_smoke_out(const tripoint &examp, const time_point &start_time)
Definition: iexamine.cpp:5728

References age(), birthday(), get_map(), anonymous_namespace{iexamine_elevator.cpp}::elevator::here(), item_counter, and iexamine::on_smoke_out().

Referenced by process_internal().

◆ process_internal()

bool item::process_internal ( player carrier,
const tripoint pos,
bool  activate,
bool  seals,
temperature_flag  flag,
const weather_manager weather_generator 
)
private

Definition at line 9655 of file item.cpp.

9658{
9659 if( has_flag( flag_ETHEREAL_ITEM ) ) {
9660 if( !has_var( "ethereal" ) ) {
9661 return true;
9662 }
9663 set_var( "ethereal", std::stoi( get_var( "ethereal" ) ) - 1 );
9664 const bool processed = std::stoi( get_var( "ethereal" ) ) <= 0;
9665 if( processed && carrier != nullptr ) {
9666 carrier->add_msg_if_player( _( "Your %s disappears!" ), tname() );
9667 }
9668 return processed;
9669 }
9670
9671 if( faults.count( fault_gun_blackpowder ) ) {
9672 return process_blackpowder_fouling( carrier );
9673 }
9674
9675 avatar &you = get_avatar();
9676 if( activate ) {
9677 return type->invoke( carrier != nullptr ? *carrier : you, *this, pos );
9678 }
9679 // How this works: it checks what kind of processing has to be done
9680 // (e.g. for food, for drying towels, lit cigars), and if that matches,
9681 // call the processing function. If that function returns true, the item
9682 // has been destroyed by the processing, so no further processing has to be
9683 // done.
9684 // Otherwise processing continues. This allows items that are processed as
9685 // food and as litcig and as ...
9686
9687 // Remaining stuff is only done for active items.
9688 if( !active ) {
9689 return false;
9690 }
9691
9692 if( !is_food() && item_counter > 0 ) {
9693 item_counter--;
9694 }
9695
9696 if( item_counter == 0 && type->countdown_action ) {
9697 type->countdown_action.call( carrier ? *carrier : you, *this, false, pos );
9698 if( type->countdown_destroy ) {
9699 return true;
9700 }
9701 }
9702
9703 map &here = get_map();
9704 for( const emit_id &e : type->emits ) {
9705 here.emit_field( pos, e );
9706 }
9707
9708 if( has_flag( flag_FAKE_SMOKE ) && process_fake_smoke( carrier, pos ) ) {
9709 return true;
9710 }
9711 if( has_flag( flag_FAKE_MILL ) && process_fake_mill( carrier, pos ) ) {
9712 return true;
9713 }
9714 if( is_corpse() && process_corpse( carrier, pos ) ) {
9715 return true;
9716 }
9717 if( has_flag( flag_WET ) && process_wet( carrier, pos ) ) {
9718 // Drying items are never destroyed, but we want to exit so they don't get processed as tools.
9719 return false;
9720 }
9721 if( has_flag( flag_LITCIG ) && process_litcig( carrier, pos ) ) {
9722 return true;
9723 }
9725 process_extinguish( carrier, pos ) ) {
9726 return false;
9727 }
9728 if( has_flag( flag_CABLE_SPOOL ) ) {
9729 // DO NOT process this as a tool! It really isn't!
9730 return process_cable( carrier, pos );
9731 }
9732 if( has_flag( flag_IS_UPS ) ) {
9733 // DO NOT process this as a tool! It really isn't!
9734 return process_UPS( carrier, pos );
9735 }
9736 if( is_tool() ) {
9737 return process_tool( carrier, pos );
9738 }
9739 // All foods that go bad have temperature
9740 if( ( is_food() || is_corpse() ) &&
9741 process_rot( seals, pos, carrier, flag, weather_generator ) ) {
9742 if( is_comestible() ) {
9743 here.rotten_item_spawn( *this, pos );
9744 }
9745 return true;
9746 }
9747
9748 return false;
9749}
bool process_fake_mill(player *carrier, const tripoint &pos)
Definition: item.cpp:9188
bool process_UPS(player *carrier, const tripoint &pos)
Definition: item.cpp:9465
bool process_corpse(player *carrier, const tripoint &pos)
Definition: item.cpp:9149
bool process_wet(player *carrier, const tripoint &pos)
Definition: item.cpp:9483
bool process_blackpowder_fouling(player *carrier)
Definition: item.cpp:9610
bool process_litcig(player *carrier, const tripoint &pos)
Definition: item.cpp:9222
bool process_extinguish(player *carrier, const tripoint &pos)
Definition: item.cpp:9297
bool process_fake_smoke(player *carrier, const tripoint &pos)
Definition: item.cpp:9205
bool process_tool(player *carrier, const tripoint &pos)
Definition: item.cpp:9496
bool process_cable(player *carrier, const tripoint &pos)
Definition: item.cpp:9392
static const std::string flag_WATER_EXTINGUISH("WATER_EXTINGUISH")
static const std::string flag_CABLE_SPOOL("CABLE_SPOOL")
static const fault_id fault_gun_blackpowder("fault_gun_blackpowder")
static const std::string flag_IS_UPS("IS_UPS")
static const std::string flag_FAKE_MILL("FAKE_MILL")
static const std::string flag_FAKE_SMOKE("FAKE_SMOKE")
use_function countdown_action
Action to take when countdown expires.
Definition: itype.h:927
bool countdown_destroy
Is item destroyed after the countdown action is run?
Definition: itype.h:921
std::set< emit_id > emits
Fields to emit when item is in active state.
Definition: itype.h:902

References _, activate(), active, player::add_msg_if_player(), use_function::call(), itype::countdown_action, itype::countdown_destroy, itype::emits, fault_gun_blackpowder, faults, flag_CABLE_SPOOL(), flag_ETHEREAL_ITEM(), flag_FAKE_MILL(), flag_FAKE_SMOKE(), flag_IS_UPS(), flag_LITCIG(), flag_WATER_EXTINGUISH(), flag_WET(), flag_WIND_EXTINGUISH(), get_avatar(), get_map(), get_var(), has_flag(), has_var(), anonymous_namespace{iexamine_elevator.cpp}::elevator::here(), itype::invoke(), is_comestible(), is_corpse(), is_food(), is_tool(), item_counter, process_blackpowder_fouling(), process_cable(), process_corpse(), process_extinguish(), process_fake_mill(), process_fake_smoke(), process_litcig(), process_rot(), process_tool(), process_UPS(), process_wet(), set_var(), tname(), and type.

Referenced by process().

◆ process_litcig()

bool item::process_litcig ( player carrier,
const tripoint pos 
)
protected

Definition at line 9222 of file item.cpp.

9223{
9224 if( !one_in( 10 ) ) {
9225 return false;
9226 }
9227 process_extinguish( carrier, pos );
9228 // process_extinguish might have extinguished the item already
9229 if( !active ) {
9230 return false;
9231 }
9232 map &here = get_map();
9233 // if carried by someone:
9234 if( carrier != nullptr ) {
9235 time_duration duration = 15_seconds;
9236 if( carrier->has_trait( trait_TOLERANCE ) ) {
9237 duration = 7_seconds;
9238 } else if( carrier->has_trait( trait_LIGHTWEIGHT ) ) {
9239 duration = 30_seconds;
9240 }
9241 carrier->add_msg_if_player( m_neutral, _( "You take a puff of your %s." ), tname() );
9242 if( has_flag( flag_TOBACCO ) ) {
9243 carrier->add_effect( effect_cig, duration );
9244 } else {
9245 carrier->add_effect( effect_weed_high, duration / 2 );
9246 }
9247 carrier->moves -= 15;
9248
9249 if( ( carrier->has_effect( effect_shakes ) && one_in( 10 ) ) ) {
9250 carrier->add_msg_if_player( m_bad, _( "Your shaking hand causes you to drop your %s." ),
9251 tname() );
9252 here.add_item_or_charges( pos + point( rng( -1, 1 ), rng( -1, 1 ) ), *this );
9253 return true; // removes the item that has just been added to the map
9254 }
9255
9256 if( carrier->has_effect( effect_sleep ) ) {
9257 carrier->add_msg_if_player( m_bad, _( "You fall asleep and drop your %s." ),
9258 tname() );
9259 here.add_item_or_charges( pos + point( rng( -1, 1 ), rng( -1, 1 ) ), *this );
9260 return true; // removes the item that has just been added to the map
9261 }
9262 } else {
9263 // If not carried by someone, but laying on the ground:
9264 if( item_counter % 5 == 0 ) {
9265 // lit cigarette can start fires
9266 if( here.flammable_items_at( pos ) ||
9267 here.has_flag( flag_FLAMMABLE, pos ) ||
9268 here.has_flag( flag_FLAMMABLE_ASH, pos ) ) {
9269 here.add_field( pos, fd_fire, 1 );
9270 }
9271 }
9272 }
9273
9274 // cig dies out
9275 if( item_counter == 0 ) {
9276 if( carrier != nullptr ) {
9277 carrier->add_msg_if_player( m_neutral, _( "You finish your %s." ), tname() );
9278 }
9279 if( typeId() == itype_cig_lit ) {
9281 } else if( typeId() == itype_cigar_lit ) {
9283 } else { // joint
9285 if( carrier != nullptr ) {
9286 carrier->add_effect( effect_weed_high, 1_minutes ); // one last puff
9287 here.add_field( pos + point( rng( -1, 1 ), rng( -1, 1 ) ), fd_weedsmoke, 2 );
9288 weed_msg( *carrier );
9289 }
9290 }
9291 active = false;
9292 }
9293 // Item remains
9294 return false;
9295}
void add_effect(const effect &eff, bool force=false, bool deferred=false)
Definition: creature.cpp:1008
bool has_effect(const efftype_id &eff_id, body_part bp=num_bp) const
Check if creature has the matching effect.
Definition: creature.cpp:1207
void weed_msg(player &p)
Handles the large variety of weed messages.
Definition: effect.cpp:78
field_type_id fd_fire
Definition: field_type.cpp:345
field_type_id fd_weedsmoke
Definition: field_type.cpp:368
static const efftype_id effect_weed_high("weed_high")
static const trait_id trait_TOLERANCE("TOLERANCE")
static const trait_id trait_LIGHTWEIGHT("LIGHTWEIGHT")
static const std::string flag_FLAMMABLE("FLAMMABLE")
static const efftype_id effect_cig("cig")
static const efftype_id effect_sleep("sleep")
static const std::string flag_FLAMMABLE_ASH("FLAMMABLE_ASH")
static const std::string flag_TOBACCO("TOBACCO")
static const efftype_id effect_shakes("shakes")
Definition: point.h:35

References _, active, Creature::add_effect(), player::add_msg_if_player(), convert(), effect_cig, effect_shakes, effect_sleep, effect_weed_high, fd_fire, fd_weedsmoke, flag_FLAMMABLE(), flag_FLAMMABLE_ASH(), flag_TOBACCO(), get_map(), Creature::has_effect(), has_flag(), Character::has_trait(), anonymous_namespace{iexamine_elevator.cpp}::elevator::here(), item_counter, itype_cig_butt, itype_cig_lit, itype_cigar_butt, itype_cigar_lit, itype_joint_roach, m_bad, m_neutral, Creature::moves, one_in(), process_extinguish(), rng(), tname(), trait_LIGHTWEIGHT, trait_TOLERANCE, typeId(), and weed_msg().

Referenced by process_internal().

◆ process_relic()

void item::process_relic ( Character carrier)

Definition at line 9133 of file item.cpp.

9134{
9135 if( !is_relic() ) {
9136 return;
9137 }
9138 std::vector<enchantment> active_enchantments;
9139
9140 for( const enchantment &ench : get_enchantments() ) {
9141 if( ench.is_active( carrier, *this ) ) {
9142 active_enchantments.emplace_back( ench );
9143 }
9144 }
9145
9146 relic_funcs::process_recharge( *this, carrier );
9147}
void process_recharge(item &itm, Character &carrier)
Definition: relic.cpp:449

References get_enchantments(), is_relic(), and relic_funcs::process_recharge().

Referenced by Character::process_turn().

◆ process_rot() [1/2]

bool item::process_rot ( bool  seals,
const tripoint pos,
player carrier,
temperature_flag  flag,
const weather_manager weather_generator 
)

Definition at line 8996 of file item.cpp.

8999{
9000 const time_point now = calendar::turn;
9001
9002 // if player debug menu'd the time backward it breaks stuff, just reset the
9003 // last_temp_check and last_rot_check in this case
9004 if( now - last_rot_check < 0_turns ) {
9005 last_rot_check = now;
9006 return false;
9007 }
9008
9009 // process rot at most once every 100_turns (10 min)
9010 // note we're also gated by item::processing_speed
9011 time_duration smallest_interval = 10_minutes;
9012
9013 units::temperature temp = units::from_fahrenheit( weather.get_temperature( pos ) );
9014 temp = clip_by_temperature_flag( temp, flag );
9015
9018
9019 if( now - time > 1_hours ) {
9020 // This code is for items that were left out of reality bubble for long time
9021
9022 const weather_generator &wgen = weather.get_cur_weather_gen();
9023 const unsigned int seed = g->get_seed();
9024 // It's a modifier, so we need to subtract 0_f
9025 units::temperature local_mod = units::from_fahrenheit( g->new_game
9026 ? 0
9027 : get_map().get_temperature( pos ) ) - 0_f;
9028
9029 // Process the past of this item since the last time it was processed
9030 while( now - time > 1_hours ) {
9031 // Get the environment temperature
9032 time_duration time_delta = std::min( 1_hours, now - 1_hours - time );
9033 time += time_delta;
9034
9035 //Use weather if above ground, use map temp if below
9036 units::temperature env_temperature_raw;
9037 if( pos.z >= 0 ) {
9038 tripoint_abs_ms location = tripoint_abs_ms( get_map().getabs( pos ) );
9039 units::temperature weather_temperature = wgen.get_weather_temperature( location, time,
9041 env_temperature_raw = weather_temperature + local_mod;
9042 } else {
9043 env_temperature_raw = units::from_fahrenheit( AVERAGE_ANNUAL_TEMPERATURE ) + local_mod;
9044 }
9045
9046 units::temperature env_temperature_clipped = clip_by_temperature_flag( env_temperature_raw, flag );
9047
9048 // Lookup table is in F
9049 int final_temperature_in_fahrenheit = static_cast<int>( std::round( units::to_fahrenheit<float>
9050 ( env_temperature_clipped ) ) );
9051
9052 // Calculate item rot
9053 rot += calc_rot( time, final_temperature_in_fahrenheit );
9055
9056 if( has_rotten_away() && carrier == nullptr && !seals ) {
9057 // No need to track item that will be gone
9058 return true;
9059 }
9060 }
9061 }
9062
9063 // Remaining <1 h from above
9064 // and items that are held near the player
9065 if( now - time > smallest_interval ) {
9066 int final_temperature_in_fahrenheit = static_cast<int>( std::round( units::to_fahrenheit<float>
9067 ( temp ) ) );
9068
9069 rot += calc_rot( now, final_temperature_in_fahrenheit );
9070 last_rot_check = now;
9071
9072 return has_rotten_away() && carrier == nullptr && !seals;
9073 }
9074 // If we're still here, mark how cold it is so we can apply tagtext to items
9075 // FIXME: this might cause issues with performance, move the comparision
9076 // directly to item::tname once #2250 lands
9077 if( temp <= temperatures::freezing ) {
9080 } else if( temp <= temperatures::root_cellar ) {
9083 } else {
9086 }
9087
9088 return false;
9089}
time_duration calc_rot(time_point time, int temp) const
Returns rot of the item since last rot calculation.
Definition: item.cpp:5677
bool has_rotten_away() const
Whether the item has enough rot that it should get removed.
Definition: item.cpp:8812
A point in the game time.
Definition: calendar.h:431
units::temperature get_weather_temperature(const tripoint_abs_ms &, const time_point &, const calendar_config &calendar_config, unsigned) const
coords::coord_point< tripoint, coords::origin::abs, coords::ms > tripoint_abs_ms
Definition: coordinates.h:486
static constexpr int AVERAGE_ANNUAL_TEMPERATURE
Average annual temperature in F used for climate, weather and temperature calculation.
static units::temperature clip_by_temperature_flag(units::temperature temperature, temperature_flag flag)
Definition: item.cpp:8973
static const std::string flag_VERY_COLD("VERY_COLD")
static const std::string flag_COLD("COLD")
calendar_config config
int seed(player *, item *, bool, const tripoint &)
Definition: iuse.cpp:5972
constexpr units::temperature freezing
constexpr units::temperature root_cellar
constexpr quantity< value_type, temperature_in_millidegree_celsius_tag > from_fahrenheit(const value_type v)
int z
Definition: point.h:138

References AVERAGE_ANNUAL_TEMPERATURE, calc_rot(), clip_by_temperature_flag(), calendar::config, flag_COLD(), flag_VERY_COLD(), temperatures::freezing, units::from_fahrenheit(), g, get_map(), weather_generator::get_weather_temperature(), has_rotten_away(), last_rot_check, temperatures::root_cellar, iuse::seed(), set_flag(), time, calendar::turn, unset_flag(), and tripoint::z.

◆ process_rot() [2/2]

bool item::process_rot ( const tripoint pos)

Update temperature for things like food Update rot for things that perish All items that rot also have temperature.

Parameters
sealsWether the item is in sealed container
posThe current position
carrierThe current carrier
flagto specify special temperature situations
weather_generatorweather manager, mostly for testing
Returns
true if the item is fully rotten and is ready to be removed

Definition at line 8968 of file item.cpp.

8969{
8970 return process_rot( false, pos, nullptr, temperature_flag::TEMP_NORMAL, get_weather() );
8971}

References get_weather(), process_rot(), and TEMP_NORMAL.

Referenced by actualize_rot(), process_internal(), and process_rot().

◆ process_tool()

bool item::process_tool ( player carrier,
const tripoint pos 
)
protected

Definition at line 9496 of file item.cpp.

9497{
9498 avatar &you = get_avatar();
9499 // items with iuse set_transformed which are restricted turn off if not attached to their dependency.
9500 if( type->can_use( "set_transformed" ) ) {
9501 const set_transformed_iuse *actor = dynamic_cast<const set_transformed_iuse *>
9502 ( this->get_use( "set_transformed" )->get_actor_ptr() );
9503 if( actor == nullptr ) {
9504 debugmsg( "iuse_actor type descriptor and actual type mismatch" );
9505 return false;
9506 }
9507 if( actor->restricted ) {
9508 if( !carrier ) {
9509 actor->bypass( carrier != nullptr ? *carrier : you, *this, false, pos );
9510 return false;
9511 } else {
9512 bool active = false;
9513 std::string transform_flag = actor->dependencies;
9514 for( const auto &elem : carrier->worn ) {
9515 if( elem.active && elem.has_flag( transform_flag ) ) {
9516 active = true;
9517 break;
9518 }
9519 }
9520 if( !active ) {
9521 actor->bypass( carrier != nullptr ? *carrier : you, *this, false, pos );
9522 return false;
9523 }
9524 }
9525 }
9526 }
9527
9528 int energy = 0;
9529 if( type->tool->turns_per_charge > 0 &&
9530 to_turn<int>( calendar::turn ) % type->tool->turns_per_charge == 0 ) {
9531 energy = std::max( ammo_required(), 1 );
9532
9533 } else if( type->tool->power_draw > 0 ) {
9534 // power_draw in mW / 1000000 to give kJ (battery unit) per second
9535 energy = type->tool->power_draw / 1000000;
9536 // energy_bat remainder results in chance at additional charge/discharge
9537 energy += x_in_y( type->tool->power_draw % 1000000, 1000000 ) ? 1 : 0;
9538 }
9539 energy -= ammo_consume( energy, pos );
9540
9541 // for power armor pieces, try to use power armor interface first.
9542 if( carrier && is_power_armor() && character_funcs::can_interface_armor( *carrier ) ) {
9543 if( carrier->use_charges_if_avail( itype_bio_armor, energy ) ) {
9544 energy = 0;
9545 }
9546 }
9547
9548 // for items in player possession if insufficient charges within tool try UPS
9549 if( carrier && ( has_flag( flag_USE_UPS ) ) ) {
9550 if( carrier->use_charges_if_avail( itype_UPS, energy ) ) {
9551 energy = 0;
9552 }
9553 }
9554
9555 // if insufficient available charges shutdown the tool
9556 if( energy > 0 ) {
9557 if( carrier ) {
9558 if( is_power_armor() ) {
9559 if( has_flag( flag_USE_UPS ) ) {
9560 carrier->add_msg_if_player( m_info, _( "You need a UPS or Bionic Power Interface to run the %s!" ),
9561 tname() );
9562 } else {
9563 carrier->add_msg_if_player( m_info, _( "You need a Bionic Power Interface to run the %s!" ),
9564 tname() );
9565 }
9566 } else if( has_flag( flag_USE_UPS ) ) {
9567 carrier->add_msg_if_player( m_info, _( "You need a UPS to run the %s!" ), tname() );
9568 }
9569 }
9570 if( carrier && type->can_use( "set_transform" ) ) {
9571 const set_transform_iuse *actor = dynamic_cast<const set_transform_iuse *>
9572 ( this->get_use( "set_transform" )->get_actor_ptr() );
9573 if( actor == nullptr ) {
9574 debugmsg( "iuse_actor type descriptor and actual type mismatch." );
9575 return false;
9576 }
9577 std::string transformed_flag = actor->flag;
9578 for( auto &elem : carrier->worn ) {
9579 if( elem.active && elem.has_flag( transformed_flag ) ) {
9580 if( !elem.type->can_use( "set_transformed" ) ) {
9581 debugmsg( "Expected set_transformed function" );
9582 return false;
9583 }
9584 const set_transformed_iuse *actor = dynamic_cast<const set_transformed_iuse *>
9585 ( elem.get_use( "set_transformed" )->get_actor_ptr() );
9586 if( actor == nullptr ) {
9587 debugmsg( "iuse_actor type descriptor and actual type mismatch" );
9588 return false;
9589 }
9590 actor->bypass( *carrier, elem, false, pos );
9591 }
9592 }
9593 }
9594
9595 // invoking the object can convert the item to another type
9596 const bool had_revert_to = type->tool->revert_to.has_value();
9597 type->invoke( carrier != nullptr ? *carrier : you, *this, pos );
9598 if( had_revert_to ) {
9599 deactivate( carrier );
9600 return false;
9601 } else {
9602 return true;
9603 }
9604 }
9605
9606 type->tick( carrier != nullptr ? *carrier : you, *this, pos );
9607 return false;
9608}
bool use_charges_if_avail(const itype_id &it, int quantity)
Definition: character.cpp:9655
item & deactivate(const Character *ch=nullptr, bool alert=true)
Filter converting this instance to the inactive type If the item is either inactive or cannot be deac...
Definition: item.cpp:544
This is a iuse_transform that changes a set of items with a specific flag.
Definition: iuse_actor.h:318
std::string flag
Flag string so we know what the heck we're transforming.
Definition: iuse_actor.h:328
static const itype_id itype_UPS("UPS")
static const itype_id itype_bio_armor("bio_armor")
bool can_interface_armor(const Character &who)
Check whether character has an active bionic capable of interfacing with power armor.
void tick(player &p, item &it, const tripoint &pos) const
Definition: itype.cpp:172

References _, active, player::add_msg_if_player(), ammo_consume(), ammo_required(), set_transformed_iuse::bypass(), character_funcs::can_interface_armor(), itype::can_use(), deactivate(), debugmsg, set_transformed_iuse::dependencies, energy, set_transform_iuse::flag, flag_USE_UPS(), use_function::get_actor_ptr(), get_avatar(), get_use(), has_flag(), itype::invoke(), is_power_armor(), itype_bio_armor, itype_UPS, m_info, set_transformed_iuse::restricted, itype::tick(), tname(), itype::tool, calendar::turn, type, Character::use_charges_if_avail(), Character::worn, and x_in_y().

Referenced by process_internal().

◆ process_UPS()

bool item::process_UPS ( player carrier,
const tripoint pos 
)
protected

Definition at line 9465 of file item.cpp.

9466{
9467 if( carrier == nullptr ) {
9468 erase_var( "cable" );
9469 active = false;
9470 return false;
9471 }
9472 bool has_connected_cable = carrier->has_item_with( []( const item & it ) {
9473 return it.active && it.has_flag( flag_CABLE_SPOOL ) && ( it.get_var( "state" ) == "UPS_link" ||
9474 it.get_var( "state" ) == "UPS" );
9475 } );
9476 if( !has_connected_cable ) {
9477 erase_var( "cable" );
9478 active = false;
9479 }
9480 return false;
9481}

References active, erase_var(), flag_CABLE_SPOOL(), get_var(), has_flag(), and visitable< T >::has_item_with().

Referenced by process_internal().

◆ process_wet()

bool item::process_wet ( player carrier,
const tripoint pos 
)
protected

Definition at line 9483 of file item.cpp.

9484{
9485 if( item_counter == 0 ) {
9486 if( is_tool() && type->tool->revert_to ) {
9487 convert( *type->tool->revert_to );
9488 }
9489 unset_flag( "WET" );
9490 active = false;
9491 }
9492 // Always return true so our caller will bail out instead of processing us as a tool.
9493 return true;
9494}

References active, convert(), is_tool(), item_counter, itype::tool, type, and unset_flag().

Referenced by process_internal().

◆ processing_speed()

int item::processing_speed ( ) const

The rate at which an item should be processed, in number of turns between updates.

Definition at line 8959 of file item.cpp.

8960{
8961 if( is_corpse() || is_food() || is_food_container() ) {
8962 return to_turns<int>( 10_minutes );
8963 }
8964 // Unless otherwise indicated, update every turn.
8965 return 1;
8966}

References is_corpse(), is_food(), and is_food_container().

Referenced by active_item_cache::add().

◆ put_in()

◆ qualities_info()

void item::qualities_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3249 of file item.cpp.

3251{
3252 auto name_quality = [&info]( const std::pair<quality_id, int> &q ) {
3253 std::string str;
3254 if( q.first == qual_JACK || q.first == qual_LIFT ) {
3255 str = string_format( _( "Has level <info>%1$d %2$s</info> quality and "
3256 "is rated at <info>%3$d</info> %4$s" ),
3257 q.second, q.first.obj().name,
3258 static_cast<int>( convert_weight( q.second * TOOL_LIFT_FACTOR ) ),
3259 weight_units() );
3260 } else {
3261 str = string_format( _( "Has level <info>%1$d %2$s</info> quality." ),
3262 q.second, q.first.obj().name );
3263 }
3264 info.emplace_back( "QUALITIES", "", str );
3265 };
3266
3267 if( parts->test( iteminfo_parts::QUALITIES ) ) {
3269 for( const std::pair<const quality_id, int> q : sorted_lex( type->qualities ) ) {
3270 name_quality( q );
3271 }
3272 }
3273
3275 contents.has_any_with( []( const item & e ) {
3276 return !e.type->qualities.empty();
3277 } ) ) {
3278
3279 info.emplace_back( "QUALITIES", "", _( "Contains items with qualities:" ) );
3280 std::map<quality_id, int, quality_id::LexCmp> most_quality;
3281 for( const item *e : contents.all_items_top() ) {
3282 for( const std::pair<const quality_id, int> &q : e->type->qualities ) {
3283 auto emplace_result = most_quality.emplace( q );
3284 if( !emplace_result.second &&
3285 most_quality.at( emplace_result.first->first ) < q.second ) {
3286 most_quality[ q.first ] = q.second;
3287 }
3288 }
3289 }
3290 for( const std::pair<const quality_id, int> &q : most_quality ) {
3291 name_quality( q );
3292 }
3293 }
3294}
bool has_any_with(const std::function< bool(const item &)> &filter) const
#define TOOL_LIFT_FACTOR
static const quality_id qual_JACK("JACK")
static const quality_id qual_LIFT("LIFT")

References _, item_contents::all_items_top(), contents, convert_weight(), item_contents::has_any_with(), info(), insert_separation_line(), qual_JACK, qual_LIFT, QUALITIES, itype::qualities, QUALITIES_CONTAINED, sorted_lex(), string_format(), iteminfo_query::test(), TOOL_LIFT_FACTOR, type, and weight_units().

Referenced by info().

◆ quality_of()

const std::map< quality_id, int > & item::quality_of ( ) const

The ids of all the qualities this contains.

Definition at line 6447 of file item.cpp.

6448{
6449 return type->qualities;
6450}

References itype::qualities, and type.

◆ reach_range()

int item::reach_range ( const Character guy) const

Max range of melee attack this weapon can be used for.

Accounts for character's abilities and installed gun mods. Guaranteed to be at least 1

Definition at line 5291 of file item.cpp.

5292{
5293 int res = 1;
5294
5295 if( has_flag( flag_REACH_ATTACK ) ) {
5296 res = has_flag( flag_REACH3 ) ? 3 : 2;
5297 }
5298
5299 // for guns consider any attached gunmods
5300 if( is_gun() && !is_gunmod() ) {
5301 for( const std::pair<const gun_mode_id, gun_mode> &m : gun_all_modes() ) {
5302 if( guy.is_npc() && m.second.flags.count( "NPC_AVOID" ) ) {
5303 continue;
5304 }
5305 if( m.second.melee() ) {
5306 res = std::max( res, m.second.qty );
5307 }
5308 }
5309 }
5310
5311 return std::max( 1, res );
5312}
virtual bool is_npc() const
Definition: creature.h:98

References flag_REACH3(), flag_REACH_ATTACK(), gun_all_modes(), has_flag(), is_gun(), is_gunmod(), and Creature::is_npc().

Referenced by avatar_action::autoattack(), fire(), npc::invalidate_range_cache(), Character::melee_attack(), npc_ai::melee_value(), npc::method_of_attack(), and target_handler::mode_reach().

◆ ready_to_revive()

bool item::ready_to_revive ( const tripoint pos) const

Whether this corpse should revive now.

Note that this function includes some randomness, the return value can differ on successive calls.

Parameters
posThe location of the item (see REVIVE_SPECIAL flag).

Definition at line 5991 of file item.cpp.

5992{
5993 if( !can_revive() ) {
5994 return false;
5995 }
5996 if( get_map().veh_at( pos ) ) {
5997 return false;
5998 }
5999 if( !calendar::once_every( 1_seconds ) ) {
6000 return false;
6001 }
6002 int age_in_hours = to_hours<int>( age() );
6003 age_in_hours -= static_cast<int>( static_cast<float>( burnt ) / ( volume() / 250_ml ) );
6004 if( damage_level( 4 ) > 0 ) {
6005 age_in_hours /= ( damage_level( 4 ) + 1 );
6006 }
6007 int rez_factor = 48 - age_in_hours;
6008 if( age_in_hours > 6 && ( rez_factor <= 0 || one_in( rez_factor ) ) ) {
6009 // If we're a special revival zombie, wait to get up until the player is nearby.
6010 const bool isReviveSpecial = has_flag( flag_REVIVE_SPECIAL );
6011 if( isReviveSpecial ) {
6012 const int distance = rl_dist( pos, get_player_character().pos() );
6013 if( distance > 3 ) {
6014 return false;
6015 }
6016 if( !one_in( distance + 1 ) ) {
6017 return false;
6018 }
6019 }
6020
6021 return true;
6022 }
6023 return false;
6024}
static const std::string flag_REVIVE_SPECIAL("REVIVE_SPECIAL")
bool once_every(const time_duration &event_frequency)
Predicate to handle rate-limiting.
Definition: calendar.cpp:490

References age(), burnt, can_revive(), damage_level(), flag_REVIVE_SPECIAL(), get_map(), get_player_character(), has_flag(), calendar::once_every(), one_in(), rl_dist(), and volume().

Referenced by process_corpse().

◆ reinforceable()

bool item::reinforceable ( ) const

Whether the item can be repaired beyond normal health.

Definition at line 6525 of file item.cpp.

6526{
6527 if( is_null() || has_flag( flag_NO_REPAIR ) ) {
6528 return false;
6529 }
6530
6531 // If a material is reinforceable, so are we
6532 const std::vector<const material_type *> &mats = made_of_types();
6533 return std::any_of( mats.begin(), mats.end(), []( const material_type * mt ) {
6534 return mt->reinforces();
6535 } );
6536}
static const std::string flag_NO_REPAIR("NO_REPAIR")

References flag_NO_REPAIR(), has_flag(), is_null(), and made_of_types().

Referenced by repair_item_actor::can_repair_target(), repair_item_actor::repair(), and repair_info().

◆ release_monster()

bool item::release_monster ( const tripoint target,
int  radius = 0 
)

Definition at line 9197 of file iuse.cpp.

9198{
9199 shared_ptr_fast<monster> new_monster = make_shared_fast<monster>();
9200 try {
9201 ::deserialize( *new_monster, get_var( "contained_json", "" ) );
9202 } catch( const std::exception &e ) {
9203 debugmsg( _( "Error restoring monster: %s" ), e.what() );
9204 return false;
9205 }
9206 if( !g->place_critter_around( new_monster, target, radius ) ) {
9207 return false;
9208 }
9209 erase_var( "contained_name" );
9210 erase_var( "contained_json" );
9211 erase_var( "name" );
9212 erase_var( "weight" );
9213 return true;
9214}
void deserialize(JsonIn &jsin)
std::shared_ptr< T > shared_ptr_fast
Definition: memory_fast.h:16

References _, debugmsg, deserialize(), erase_var(), g, and get_var().

Referenced by iuse::capture_monster_act(), and DefaultRemovePartHandler::spawn_animal_from_part().

◆ reload()

bool item::reload ( player u,
item_location  loc,
int  qty 
)

Reload item using ammo from location returning true if successful.

Parameters
uPlayer doing the reloading
locLocation of ammo to be reloaded
qtycaps reloading to this (or fewer) units

Definition at line 8128 of file item.cpp.

8129{
8130 if( qty <= 0 ) {
8131 debugmsg( "Tried to reload zero or less charges" );
8132 return false;
8133 }
8134 item *ammo = loc.get_item();
8135 if( ammo == nullptr || ammo->is_null() ) {
8136 debugmsg( "Tried to reload using non-existent ammo" );
8137 return false;
8138 }
8139
8140 item *container = nullptr;
8141 if( ammo->is_ammo_container() || ammo->is_container() ) {
8142 container = ammo;
8143 ammo = &ammo->contents.front();
8144 }
8145
8146 if( !is_reloadable_with( ammo->typeId() ) ) {
8147 return false;
8148 }
8149
8150 // limit quantity of ammo loaded to remaining capacity
8151 int limit = is_watertight_container()
8154
8155 if( ammo->ammo_type() == ammo_plutonium ) {
8156 limit = limit / PLUTONIUM_CHARGES + ( limit % PLUTONIUM_CHARGES != 0 );
8157 }
8158
8159 qty = std::min( qty, limit );
8160
8161 casings_handle( [&u]( item & e ) {
8162 return u.i_add_or_drop( e );
8163 } );
8164
8165 if( is_magazine() ) {
8166 qty = std::min( qty, ammo->charges );
8167
8168 if( is_ammo_belt() && type->magazine->linkage ) {
8169 if( !u.use_charges_if_avail( *type->magazine->linkage, qty ) ) {
8170 debugmsg( "insufficient linkages available when reloading ammo belt" );
8171 }
8172 }
8173
8174 item to_reload = *ammo;
8175 to_reload.charges = qty;
8176 ammo->charges -= qty;
8177 bool merged = false;
8178 for( item *it : contents.all_items_top() ) {
8179 if( it->merge_charges( to_reload ) ) {
8180 merged = true;
8181 break;
8182 }
8183 }
8184 if( !merged ) {
8185 put_in( to_reload );
8186 }
8187 } else if( is_watertight_container() ) {
8188 if( !ammo->made_of( LIQUID ) ) {
8189 debugmsg( "Tried to reload liquid container with non-liquid." );
8190 return false;
8191 }
8192 if( container ) {
8193 container->on_contents_changed();
8194 }
8195 fill_with( *ammo, qty );
8196 } else if( !magazine_integral() ) {
8197 // if we already have a magazine loaded prompt to eject it
8198 if( magazine_current() ) {
8199 //~ %1$s: magazine name, %2$s: weapon name
8200 std::string prompt = string_format( pgettext( "magazine", "Eject %1$s from %2$s?" ),
8201 magazine_current()->tname(), tname() );
8202
8203 // eject magazine to player inventory and try to dispose of it from there
8204 item &mag = u.i_add( *magazine_current() );
8205 if( !u.dispose_item( item_location( u, &mag ), prompt ) ) {
8206 u.remove_item( mag ); // user canceled so delete the clone
8207 return false;
8208 }
8210 }
8211
8212 put_in( *ammo );
8213 loc.remove_item();
8214 return true;
8215
8216 } else {
8217 if( ammo->has_flag( flag_SPEEDLOADER ) ) {
8218 curammo = ammo->contents.front().type;
8219 qty = std::min( qty, ammo->ammo_remaining() );
8220 ammo->ammo_consume( qty, tripoint_zero );
8221 charges += qty;
8222 } else if( ammo->ammo_type() == ammo_plutonium ) {
8223 curammo = ammo->type;
8224 ammo->charges -= qty;
8225
8226 // any excess is wasted rather than overfilling the item
8227 charges += qty * PLUTONIUM_CHARGES;
8228 charges = std::min( charges, ammo_capacity() );
8229 } else {
8230 curammo = ammo->type;
8231 qty = std::min( qty, ammo->charges );
8232 ammo->charges -= qty;
8233 charges += qty;
8234 }
8235 }
8236
8237 if( ammo->charges == 0 && !ammo->has_flag( flag_SPEEDLOADER ) ) {
8238 if( container != nullptr ) {
8239 container->remove_item( container->contents.front() );
8240 u.inv.restack( u ); // emptied containers do not stack with non-empty ones
8241 } else {
8242 loc.remove_item();
8243 }
8244 }
8245 return true;
8246}
item & i_add(item it, bool should_stack=true)
Definition: character.cpp:2268
bool i_add_or_drop(item &it, int qty=1)
Sets invlet and adds to inventory if possible, drops otherwise, returns true if either succeeded.
Definition: character.cpp:2408
virtual bool dispose_item(item_location &&obj, const std::string &prompt=std::string())
Drop, wear, stash or otherwise try to dispose of an item consuming appropriate moves.
Definition: character.cpp:7264
void restack(player &p)
Definition: inventory.cpp:400
item * get_item()
Gets the selected item or nullptr.
void remove_item()
Removes the selected item from the game.
void fill_with(item &liquid, int amount=INFINITE_CHARGES)
Fill item with liquid up to its capacity.
Definition: item.cpp:8585
bool is_ammo_belt() const
Definition: item.cpp:6593
static constexpr int PLUTONIUM_CHARGES
static const ammotype ammo_plutonium("plutonium")
static const std::string flag_SPEEDLOADER("SPEEDLOADER")
@ prompt
Definition: pickup.h:30
static constexpr tripoint tripoint_zero
Definition: point.h:259

References item_contents::all_items_top(), ammo_capacity(), ammo_consume(), ammo_plutonium, ammo_remaining(), ammo_type(), casings_handle(), charges, contents, curammo, debugmsg, Character::dispose_item(), fill_with(), flag_SPEEDLOADER(), item_contents::front(), item_location::get_item(), get_remaining_capacity_for_liquid(), has_flag(), Character::i_add(), Character::i_add_or_drop(), Character::inv, is_ammo_belt(), is_ammo_container(), is_container(), is_magazine(), is_null(), is_reloadable_with(), is_watertight_container(), LIQUID, made_of(), itype::magazine, magazine_current(), magazine_integral(), on_contents_changed(), pgettext(), PLUTONIUM_CHARGES, pickup::prompt, put_in(), item_location::remove_item(), visitable< item >::remove_item(), visitable< T >::remove_item(), inventory::restack(), string_format(), tname(), tripoint_zero, type, typeId(), and Character::use_charges_if_avail().

Referenced by veh_interact::complete_vehicle(), npc::do_reload(), ranged::fire_gun(), and activity_handlers::reload_finish().

◆ remove_old_owner()

void item::remove_old_owner ( ) const
inline

Definition at line 2032 of file item.h.

2032 {
2034 }

References string_id< faction >::NULL_ID().

Referenced by talk_function::drop_stolen_item(), and validate_ownership().

◆ remove_owner()

void item::remove_owner ( ) const
inline

Definition at line 2039 of file item.h.

2039 {
2041 }

References string_id< faction >::NULL_ID().

Referenced by validate_ownership().

◆ repair_info()

void item::repair_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3174 of file item.cpp.

3176{
3178 return;
3179 }
3181 const std::vector<itype_id> &rep = sorted_lex( repaired_with() );
3182 if( !rep.empty() ) {
3183 info.emplace_back( "DESCRIPTION", string_format( _( "<bold>Repair</bold> using %s." ),
3184 enumerate_as_string( rep.begin(), rep.end(), []( const itype_id & e ) {
3185 return nname( e );
3187 if( reinforceable() ) {
3188 info.emplace_back( "DESCRIPTION", _( "* This item can be <good>reinforced</good>." ) );
3189 }
3190 } else {
3191 info.emplace_back( "DESCRIPTION", _( "* This item is <bad>not repairable</bad>." ) );
3192 }
3193}
bool reinforceable() const
Whether the item can be repaired beyond normal health.
Definition: item.cpp:6525
const std::set< itype_id > & repaired_with() const
If possible to repair this item what tools could potentially be used for this purpose?
Definition: item.cpp:6383

References _, DESCRIPTION_REPAIREDWITH, enumerate_as_string(), info(), insert_separation_line(), or_, reinforceable(), repaired_with(), sorted_lex(), string_format(), and iteminfo_query::test().

Referenced by info().

◆ repaired_with()

const std::set< itype_id > & item::repaired_with ( ) const

If possible to repair this item what tools could potentially be used for this purpose?

Definition at line 6383 of file item.cpp.

6384{
6385 static std::set<itype_id> no_repair;
6386 return has_flag( flag_NO_REPAIR ) ? no_repair : type->repair;
6387}
std::set< itype_id > repair
Damage scale compared to the old float damage value.
Definition: itype.h:982

References flag_NO_REPAIR(), has_flag(), itype::repair, and type.

Referenced by repair_info().

◆ reset_cable()

void item::reset_cable ( player p)

Helper to bring a cable back to its initial state.

Definition at line 9448 of file item.cpp.

9449{
9450 int max_charges = type->maximum_charges();
9451
9452 set_var( "state", "attach_first" );
9453 erase_var( "source_x" );
9454 erase_var( "source_y" );
9455 erase_var( "source_z" );
9456 active = false;
9457 charges = max_charges;
9458
9459 if( p != nullptr ) {
9460 p->add_msg_if_player( m_info, _( "You reel in the cable." ) );
9461 p->moves -= charges * 10;
9462 }
9463}

References _, active, player::add_msg_if_player(), charges, erase_var(), m_info, itype::maximum_charges(), Creature::moves, set_var(), and type.

Referenced by process_cable().

◆ rotten()

◆ serialize()

void item::serialize ( JsonOut json) const

Definition at line 2392 of file savegame_json.cpp.

2393{
2394 io::JsonObjectOutputArchive archive( json );
2395 const_cast<item *>( this )->io( archive );
2396 if( !contents.empty() ) {
2397 json.member( "contents", contents );
2398 }
2399}
void member(const std::string &name)
Definition: json.cpp:2235
Output archive matching the input archive JsonObjectInputArchive.
Definition: cata_io.h:351

References contents, item_contents::empty(), io(), and JsonOut::member().

Referenced by contain_monster().

◆ set_age()

void item::set_age ( const time_duration age)

Definition at line 10040 of file item.cpp.

10041{
10043}
void set_birthday(const time_point &bday)
Definition: item.cpp:10061

References age(), set_birthday(), and calendar::turn.

Referenced by burn(), iuse::firecracker_pack(), iuse::fish_trap(), vehicle::operate_planter(), and map::process_fields_in_submap().

◆ set_birthday()

void item::set_birthday ( const time_point bday)

Definition at line 10061 of file item.cpp.

10062{
10063 this->bday = std::max( calendar::turn_zero, bday );
10064}

References bday, and calendar::turn_zero.

Referenced by editmap::edit_itm(), retroactively_fill_from_funnel(), set_age(), and debug_menu::wishitem().

◆ set_cached_tool_selections()

void item::set_cached_tool_selections ( const std::vector< comp_selection< tool_comp > > &  selections)

Definition at line 10142 of file item.cpp.

10143{
10144 assert( craft_data_ );
10145 craft_data_->cached_tool_selections = selections;
10146}

References craft_data_.

Referenced by craft_command::create_in_progress_craft().

◆ set_countdown()

void item::set_countdown ( int  num_turns)

Sets time until activation for an item that will self-activate in the future.

Definition at line 8620 of file item.cpp.

8621{
8622 if( num_turns < 0 ) {
8623 debugmsg( "Tried to set a negative countdown value %d.", num_turns );
8624 return;
8625 }
8626 if( !ammo_types().empty() ) {
8627 debugmsg( "Tried to set countdown on an item with ammo." );
8628 return;
8629 }
8630 charges = num_turns;
8631}

References ammo_types(), charges, and debugmsg.

Referenced by iuse_transform::use().

◆ set_damage()

item & item::set_damage ( int  qty)

Filter setting damage constrained by min_damage and max_damage.

Note
this method does not invoke the on_damage callback
Returns
same instance to allow method chaining

Definition at line 718 of file item.cpp.

719{
720 on_damage( qty - damage_, DT_TRUE );
721 damage_ = std::max( std::min( qty, max_damage() ), min_damage() );
722 return *this;
723}

References damage_, DT_TRUE, max_damage(), min_damage(), and on_damage().

Referenced by mdeath::broken(), editmap::edit_itm(), iuse::gun_repair(), Item_modifier::modify(), vehicle_part::properties_to_item(), repair_item_actor::repair(), game::save_cyborg(), vehicle::set_hp(), and map::spawn_an_item().

◆ set_favorite()

void item::set_favorite ( bool  favorite)

Definition at line 10114 of file item.cpp.

10115{
10116 is_favorite = favorite;
10117}

References is_favorite.

Referenced by advanced_inventory::display(), and inventory_column::set_stack_favorite().

◆ set_flag()

item & item::set_flag ( const std::string &  flag)

Idempotent filter setting an item specific flag.

Definition at line 5358 of file item.cpp.

5359{
5360 item_tags.insert( flag );
5361 return *this;
5362}
iterator insert(iterator, const value_type &value)
Definition: flat_set.h:151

References cata::flat_set< T, Compare, Data >::insert(), and item_tags.

Referenced by map::add_corpse(), ammo_set(), are_requirements_nearby(), iexamine::autodoc(), explosion_handler::ExplosionProcess::blast_tile(), butcher_cbm_item(), activity_handlers::butcher_finish(), butchery_quarter(), iuse::camera(), complete_craft(), crafting::complete_disassemble(), recipe::create_byproducts(), Single_item_creator::create_single(), cycle_action(), game::dump_stats(), Character::eat(), heal_actor::finish_using(), basecamp::form_crafting_inventory(), inventory::form_from_map(), activity_handlers::repair_activity_hack::anonymous_namespace{activity_handlers.cpp}::get_fake_tool(), iuse_transform::info(), inherit_flags(), init_memory_card_with_random_stuff(), item(), Item_factory::migrate_item(), Item_modifier::modify(), explosion_handler::ExplosionProcess::move_entity(), iexamine::nanofab(), on_damage(), on_drop(), process_rot(), vehicle_part::properties_to_item(), iuse::radio_mod(), activity_handlers::reload_finish(), repair_item_actor::repair(), mattack::riotbot(), set_flag_recursive(), spell_effect::spawn_ethereal_item(), map::spawn_item(), starting_clothes(), starting_inv(), iuse::towel_common(), avatar_funcs::unload_item(), sew_advanced_actor::use(), unpack_actor::use(), iexamine::use_furn_fake_item(), and vehicle_part::vehicle_part().

◆ set_flag_recursive()

item & item::set_flag_recursive ( const std::string &  flag)

Idempotent filter recursively setting an item specific flag on this item and its components.

Definition at line 5370 of file item.cpp.

5371{
5372 set_flag( flag );
5373 for( item &comp : components ) {
5374 comp.set_flag_recursive( flag );
5375 }
5376 return *this;
5377}

References components, and set_flag().

◆ set_mtype()

void item::set_mtype ( const mtype m)

Sets the monster type associated with this item (corpse).

You must not pass a null pointer. TODO: change this to take a reference instead.

Definition at line 6678 of file item.cpp.

6679{
6680 // This is potentially dangerous, e.g. for corpse items, which *must* have a valid mtype pointer.
6681 if( m == nullptr ) {
6682 debugmsg( "setting item::corpse of %s to NULL", tname() );
6683 return;
6684 }
6685 corpse = m;
6686}

References corpse, debugmsg, and tname().

Referenced by iuse::blood_draw().

◆ set_next_failure_point()

void item::set_next_failure_point ( const player crafter)

Calculates and sets the next failure point for an in progress craft.

Causes a debugmsg if called on non-craft.

Parameters
crafterthe crafting player

Definition at line 905 of file crafting.cpp.

906{
907 if( !is_craft() ) {
908 debugmsg( "set_next_failure_point() called on non-craft '%s.' Aborting.", tname() );
909 return;
910 }
911
912 const int percent_left = 10000000 - item_counter;
913 const int failure_point_delta = crafter.crafting_success_roll( get_making() ) * percent_left;
914
915 craft_data_->next_failure_point = item_counter + failure_point_delta;
916}

References craft_data_, player::crafting_success_roll(), debugmsg, get_making(), is_craft(), item_counter, and tname().

Referenced by craft_command::create_in_progress_craft(), and handle_craft_failure().

◆ set_old_owner()

void item::set_old_owner ( const faction_id temp_owner)
inline

Definition at line 2029 of file item.h.

2029 {
2030 old_owner = temp_owner;
2031 }

Referenced by handle_pickup_ownership().

◆ set_owner() [1/2]

void item::set_owner ( const Character c)

Definition at line 1274 of file item.cpp.

1275{
1276 if( !c.get_faction() ) {
1277 debugmsg( "item::set_owner() Character %s has no valid faction", c.disp_name() );
1278 return;
1279 }
1280 owner = c.get_faction()->id;
1281}

References c, debugmsg, and owner.

◆ set_owner() [2/2]

◆ set_relative_rot()

void item::set_relative_rot ( double  val)

Set current item rot relative to shelf life (no-op if item does not spoil)

Definition at line 5565 of file item.cpp.

5566{
5567 if( goes_bad() ) {
5568 rot = get_shelf_life() * val;
5569 // calc_rot uses last_rot_check (when it's not turn_zero) instead of bday.
5570 // this makes sure the rotting starts from now, not from bday.
5571 // if this item is the result of smoking or milling don't do this, we want to start from bday.
5574 }
5575 }
5576}
static const std::string flag_PROCESSING_RESULT("PROCESSING_RESULT")

References flag_PROCESSING_RESULT(), get_shelf_life(), goes_bad(), has_flag(), last_rot_check, and calendar::turn.

Referenced by complete_craft(), fill_with(), item(), and iexamine::keg().

◆ set_rot()

void item::set_rot ( time_duration  val)

Definition at line 5578 of file item.cpp.

5579{
5580 rot = val;
5581}

◆ set_side()

bool item::set_side ( side  s)

Change the side on which the item is worn.

Returns false if the item is not sided

Definition at line 819 of file item.cpp.

820{
821 if( !is_sided() ) {
822 return false;
823 }
824
825 if( s == side::BOTH ) {
826 erase_var( "lateral" );
827 } else {
828 set_var( "lateral", static_cast<int>( s ) );
829 }
830
831 return true;
832}

References BOTH, erase_var(), is_sided(), and set_var().

Referenced by on_takeoff(), on_wear(), and swap_side().

◆ set_snippet()

void item::set_snippet ( const snippet_id id)

Set the snippet text (description) of this specific item, using the snippet library.

See also
snippet_library.

Definition at line 8696 of file item.cpp.

8697{
8698 if( is_null() ) {
8699 return;
8700 }
8701 if( !id.is_valid() ) {
8702 debugmsg( "there's no snippet with id %s", id.str() );
8703 return;
8704 }
8705 snip_id = id;
8706}

References debugmsg, base_camps::id, is_null(), and snip_id.

Referenced by profession::items().

◆ set_tools_to_continue()

void item::set_tools_to_continue ( bool  value)

Definition at line 10130 of file item.cpp.

10131{
10132 assert( craft_data_ );
10133 craft_data_->tools_to_continue = value;
10134}

References craft_data_.

Referenced by craft_command::create_in_progress_craft().

◆ set_var() [1/6]

void item::set_var ( const std::string &  name,
const std::string &  value 
)

Definition at line 1060 of file item.cpp.

1061{
1062 item_vars[name] = value;
1063}

References item_vars, and om_direction::name().

◆ set_var() [2/6]

void item::set_var ( const std::string &  name,
const tripoint value 
)

Definition at line 1043 of file item.cpp.

1044{
1045 item_vars[name] = string_format( "%d,%d,%d", value.x, value.y, value.z );
1046}
int y
Definition: point.h:137
int x
Definition: point.h:136

References item_vars, om_direction::name(), string_format(), tripoint::x, tripoint::y, and tripoint::z.

◆ set_var() [3/6]

void item::set_var ( const std::string &  name,
double  value 
)

Definition at line 1029 of file item.cpp.

1030{
1031 item_vars[name] = string_format( "%f", value );
1032}

References item_vars, om_direction::name(), and string_format().

◆ set_var() [4/6]

◆ set_var() [5/6]

void item::set_var ( const std::string &  name,
long long  value 
)

Definition at line 1012 of file item.cpp.

1013{
1014 std::ostringstream tmpstream;
1015 tmpstream.imbue( std::locale::classic() );
1016 tmpstream << value;
1017 item_vars[name] = tmpstream.str();
1018}

References item_vars, and om_direction::name().

◆ set_var() [6/6]

void item::set_var ( const std::string &  name,
long  value 
)

Definition at line 1021 of file item.cpp.

1022{
1023 std::ostringstream tmpstream;
1024 tmpstream.imbue( std::locale::classic() );
1025 tmpstream << value;
1026 item_vars[name] = tmpstream.str();
1027}

References item_vars, and om_direction::name().

◆ sight_dispersion()

int item::sight_dispersion ( ) const

Get lowest dispersion of either integral or any attached sights.

Definition at line 7274 of file item.cpp.

7275{
7276 if( !is_gun() ) {
7277 return 0;
7278 }
7279
7280 int res = has_flag( flag_DISABLE_SIGHTS ) ? 90 : type->gun->sight_dispersion;
7281
7282 for( const item *e : gunmods() ) {
7283 const islot_gunmod &mod = *e->type->gunmod;
7284 if( mod.sight_dispersion < 0 || mod.aim_speed < 0 ) {
7285 continue; // skip gunmods which don't provide a sight
7286 }
7287 res = std::min( res, mod.sight_dispersion );
7288 }
7289
7290 return res;
7291}

References flag_DISABLE_SIGHTS(), itype::gun, gunmods(), has_flag(), is_gun(), and type.

Referenced by ranged::get_aim_types(), target_ui::panel_recoil(), print_aim(), and target_ui::run().

◆ simulate_burn()

float item::simulate_burn ( fire_data frd) const

Calculate all burning calculations, but don't actually apply them to item.

DO apply them to fire_data argument, though.

Returns
Amount of "burn" that would be applied to the item.

Definition at line 8248 of file item.cpp.

8249{
8250 const std::vector<material_id> &mats = made_of();
8251 float smoke_added = 0.0f;
8252 float time_added = 0.0f;
8253 float burn_added = 0.0f;
8254 const units::volume vol = base_volume();
8255 const int effective_intensity = frd.contained ? 3 : frd.fire_intensity;
8256 for( const material_id &m : mats ) {
8257 const mat_burn_data &bd = m.obj().burn_data( effective_intensity );
8258 if( bd.immune ) {
8259 // Made to protect from fire
8260 return 0.0f;
8261 }
8262
8263 // If fire is contained, burn rate is independent of volume
8264 if( frd.contained || bd.volume_per_turn == 0_ml ) {
8265 time_added += bd.fuel;
8266 smoke_added += bd.smoke;
8267 burn_added += bd.burn;
8268 } else {
8269 double volume_burn_rate = to_liter( bd.volume_per_turn ) / to_liter( vol );
8270 time_added += bd.fuel * volume_burn_rate;
8271 smoke_added += bd.smoke * volume_burn_rate;
8272 burn_added += bd.burn * volume_burn_rate;
8273 }
8274 }
8275
8276 // Liquids that don't burn well smother fire well instead
8277 if( made_of( LIQUID ) && time_added < 200 ) {
8278 time_added -= rng( 400.0 * to_liter( vol ), 1200.0 * to_liter( vol ) );
8279 } else if( mats.size() > 1 ) {
8280 // Average the materials
8281 time_added /= mats.size();
8282 smoke_added /= mats.size();
8283 burn_added /= mats.size();
8284 } else if( mats.empty() ) {
8285 // Non-liquid items with no specified materials will burn at moderate speed
8286 burn_added = 1;
8287 }
8288
8289 if( count_by_charges() ) {
8290 int stack_burnt = rng( type->stack_size / 2, type->stack_size );
8291 time_added *= stack_burnt;
8292 smoke_added *= stack_burnt;
8293 burn_added *= stack_burnt;
8294 }
8295
8296 frd.fuel_produced += time_added;
8297 frd.smoke_produced += smoke_added;
8298 return burn_added;
8299}
constexpr double to_liter(const volume &v)
Definition: units_volume.h:43
int fire_intensity
Current intensity of the fire.
Definition: fire.h:25
float fuel_produced
Fuel contributed by each burning item this turn is summed here.
Definition: fire.h:29
float smoke_produced
Smoke produced by each burning item this turn is summed here.
Definition: fire.h:27
bool contained
The fire is contained and burned for fuel intentionally.
Definition: fire.h:31
float smoke
Smoke produced per tick when this material burns.
Definition: fire.h:54
float burn
Volume of material destroyed per tick when this material burns.
Definition: fire.h:56

References base_volume(), mat_burn_data::burn, fire_data::contained, count_by_charges(), fire_data::fire_intensity, mat_burn_data::fuel, fire_data::fuel_produced, mat_burn_data::immune, LIQUID, made_of(), rng(), mat_burn_data::smoke, fire_data::smoke_produced, itype::stack_size, units::to_liter(), type, and mat_burn_data::volume_per_turn.

Referenced by burn(), and try_fuel_fire().

◆ spill_contents() [1/2]

bool item::spill_contents ( Character c)

Unloads the item's contents.

Parameters
cCharacter who receives the contents. If c is the player, liquids will be handled, otherwise they will be spilled.
Returns
If the item is now empty.

Definition at line 7085 of file item.cpp.

7086{
7087 if( !is_container() || is_container_empty() ) {
7088 return true;
7089 }
7090
7091 if( c.is_npc() ) {
7092 return spill_contents( c.pos() );
7093 }
7094
7097
7098 return true;
7099}
void handle_liquid_or_spill(Character &guy)
bool spill_contents(Character &c)
Unloads the item's contents.
Definition: item.cpp:7085

References c, contents, item_contents::handle_liquid_or_spill(), is_container(), is_container_empty(), on_contents_changed(), and spill_contents().

Referenced by drop_or_embed_projectile(), pickup::handle_spillable_contents(), Character::i_rem_keep_contents(), pick_one_up(), smash(), and spill_contents().

◆ spill_contents() [2/2]

bool item::spill_contents ( const tripoint pos)

Unloads the item's contents.

Parameters
posPosition to dump the contents on.
Returns
If the item is now empty.

Definition at line 7101 of file item.cpp.

7102{
7103 if( !is_container() || is_container_empty() ) {
7104 return true;
7105 }
7106
7107 for( item *it : contents.all_items_top() ) {
7108 get_map().add_item_or_charges( pos, *it );
7109 }
7110
7112 return true;
7113}
item & add_item_or_charges(const tripoint &pos, item obj, bool overflow=true)
Adds an item to map tile or stacks charges.
Definition: map.cpp:4355

References map::add_item_or_charges(), item_contents::all_items_top(), item_contents::clear_items(), contents, get_map(), is_container(), and is_container_empty().

◆ split()

item item::split ( int  qty)

Splits a count-by-charges item always leaving source item with minimum of 1 charge.

Parameters
qtynumber of required charges to split from source
Returns
new instance containing exactly qty charges or null item if splitting failed

Definition at line 725 of file item.cpp.

726{
727 if( !count_by_charges() || qty <= 0 || qty >= charges ) {
728 return item();
729 }
730 item res = *this;
731 res.charges = qty;
732 charges -= qty;
733 return res;
734}

References charges, count_by_charges(), and item().

Referenced by iexamine::gaspump(), Character::item_reload_cost(), item_location::impl::item_on_map::obtain(), item_location::impl::item_on_person::obtain(), item_location::impl::item_on_vehicle::obtain(), item_location::impl::item_in_container::obtain(), item_location::impl::item_on_map::obtain_cost(), item_location::impl::item_on_person::obtain_cost(), item_location::impl::item_on_vehicle::obtain_cost(), and bandolier_actor::reload().

◆ spoilage_sort_order()

int item::spoilage_sort_order ( ) const

Get time left to rot, ignoring fridge.

Returns time to rot if item is able to, max int - N otherwise, where N is 3 for food, 2 for medication, 1 for other comestibles, 0 otherwise.

Definition at line 5583 of file item.cpp.

5584{
5585 const item *subject;
5586 constexpr int bottom = std::numeric_limits<int>::max();
5587
5588 if( type->container && !contents.empty() ) {
5589 if( type->container->preserves ) {
5590 return bottom - 3;
5591 }
5592 subject = &contents.front();
5593 } else {
5594 subject = this;
5595 }
5596
5597 if( subject->goes_bad() ) {
5598 return to_turns<int>( subject->get_shelf_life() - subject->rot );
5599 }
5600
5601 if( subject->get_comestible() ) {
5602 if( subject->get_category().get_id() == itemcat_food ) {
5603 return bottom - 3;
5604 } else if( subject->get_category().get_id() == itemcat_drugs ) {
5605 return bottom - 2;
5606 } else {
5607 return bottom - 1;
5608 }
5609 }
5610 return bottom;
5611}
static const item_category_id itemcat_drugs("drugs")
static const item_category_id itemcat_food("food")

References itype::container, contents, item_contents::empty(), item_contents::front(), get_category(), get_comestible(), item_category::get_id(), get_shelf_life(), goes_bad(), itemcat_drugs, itemcat_food, rot, and type.

Referenced by find_auto_consume().

◆ stab_resist()

int item::stab_resist ( bool  to_self = false) const

Definition at line 6118 of file item.cpp.

6119{
6120 // Better than hardcoding it in multiple places
6121 return static_cast<int>( 0.8f * cut_resist( to_self ) );
6122}

References cut_resist().

Referenced by damage_resist().

◆ stacks_with()

bool item::stacks_with ( const item rhs,
bool  check_components = false,
bool  skip_type_check = false 
) const

Definition at line 893 of file item.cpp.

894{
895 if( !skip_type_check && type != rhs.type ) {
896 return false;
897 }
898 if( is_relic() && rhs.is_relic() && !( *relic_data == *rhs.relic_data ) ) {
899 return false;
900 }
901 if( charges != 0 && rhs.charges != 0 && is_money() ) {
902 // Dealing with nonempty cash cards
903 return true;
904 }
905 // This function is also used to test whether items counted by charges should be merged, for that
906 // check the, the charges must be ignored. In all other cases (tools/guns), the charges are important.
907 if( !count_by_charges() && charges != rhs.charges ) {
908 return false;
909 }
910 if( is_favorite != rhs.is_favorite ) {
911 return false;
912 }
913 if( damage_ != rhs.damage_ ) {
914 return false;
915 }
916 if( burnt != rhs.burnt ) {
917 return false;
918 }
919 if( active != rhs.active ) {
920 return false;
921 }
922 if( item_tags != rhs.item_tags ) {
923 return false;
924 }
925 if( faults != rhs.faults ) {
926 return false;
927 }
928 if( techniques != rhs.techniques ) {
929 return false;
930 }
931 if( item_vars != rhs.item_vars ) {
932 return false;
933 }
934 if( goes_bad() && rhs.goes_bad() ) {
935 // Stack items that fall into the same "bucket" of freshness.
936 // Distant buckets are larger than near ones.
937 std::pair<int, clipped_unit> my_clipped_time_to_rot =
939 std::pair<int, clipped_unit> other_clipped_time_to_rot =
940 clipped_time( rhs.get_shelf_life() - rhs.rot );
941 if( my_clipped_time_to_rot != other_clipped_time_to_rot ) {
942 return false;
943 }
944 if( rotten() != rhs.rotten() ) {
945 // just to be safe that rotten and unrotten food is *never* stacked.
946 return false;
947 }
948 }
949 if( ( corpse == nullptr && rhs.corpse != nullptr ) ||
950 ( corpse != nullptr && rhs.corpse == nullptr ) ) {
951 return false;
952 }
953 if( corpse != nullptr && rhs.corpse != nullptr && corpse->id != rhs.corpse->id ) {
954 return false;
955 }
956 if( craft_data_ || rhs.craft_data_ ) {
957 // In-progress crafts are always distinct items. Easier to handle for the player,
958 // and there shouldn't be that many items of this type around anyway.
959 return false;
960 }
961 if( check_components || is_comestible() || is_craft() ) {
962 //Only check if at least one item isn't using the default recipe or is comestible
963 if( !components.empty() || !rhs.components.empty() ) {
965 return false;
966 }
967 }
968 }
970 return false;
971 }
972
973 if( ammo_current() != rhs.ammo_current() ) {
974 return false;
975 }
976
977 return contents.stacks_with( rhs.contents );
978}
std::pair< int, clipped_unit > clipped_time(const time_duration &d)
Returns a value representing the passed in duration truncated to an appropriate unit along with the u...
Definition: calendar.cpp:284
bool stacks_with(const item_contents &rhs) const
std::vector< item_comp > get_uncraft_components() const
Returns a list of components used to craft this item or the default components if it wasn't player-cr...
Definition: item.cpp:10087

References active, ammo_current(), burnt, charges, clipped_time(), components, contents, corpse, count_by_charges(), craft_data_, damage_, faults, get_shelf_life(), get_uncraft_components(), goes_bad(), mtype::id, is_comestible(), is_craft(), is_favorite, is_money(), is_relic(), item_tags, item_vars, item_contents::num_item_stacks(), relic_data, rot, rotten(), item_contents::stacks_with(), techniques, and type.

Referenced by display_stacked_with(), merge_charges(), inventory::restack(), inventory_column::set_stack_favorite(), and npc_trading::transfer_items().

◆ swap_side()

bool item::swap_side ( )

Swap the side on which the item is worn.

Returns false if the item is not sided

Definition at line 834 of file item.cpp.

835{
836 return set_side( opposite_side( get_side() ) );
837}
side opposite_side(side s)
Returns the opposite side.
Definition: bodypart.cpp:30

References get_side(), opposite_side(), and set_side().

Referenced by Character::change_side().

◆ symbol()

const std::string & item::symbol ( ) const

Definition at line 4143 of file item.cpp.

4144{
4145 return type->sym;
4146}
std::string sym
Definition: itype.h:976

References itype::sym, and type.

Referenced by map::draw_maptile(), map_memory::load_legacy(), mm_elem::operator==(), pickup::pick_up(), mm_submap::serialize(), and debug_menu::wishitem().

◆ tname()

std::string item::tname ( unsigned int  quantity = 1,
bool  with_prefix = true,
unsigned int  truncate = 0 
) const

Return the (translated) item name.

Parameters
quantityused for translation to the proper plural form of the name, e.g. returns "rock" for quantity 1 and "rocks" for quantity > 0.
with_prefixdetermines whether to include more item properties, such as the extent of damage and burning (was created to sort by name without prefix in additional inventory)

Definition at line 4575 of file item.cpp.

4576{
4577 int dirt_level = get_var( "dirt", 0 ) / 2000;
4578 std::string dirt_symbol;
4579 // TODO: MATERIALS put this in json
4580
4581 // these symbols are unicode square characeters of different heights, representing a rough
4582 // estimation of fouling in a gun. This appears instead of "faulty"
4583 // since most guns will have some level of fouling in them, and usually it is not a big deal.
4584 switch( dirt_level ) {
4585 case 0:
4586 dirt_symbol = "";
4587 break;
4588 case 1:
4589 dirt_symbol = "<color_white>\u2581</color>";
4590 break;
4591 case 2:
4592 dirt_symbol = "<color_light_gray>\u2583</color>";
4593 break;
4594 case 3:
4595 dirt_symbol = "<color_light_gray>\u2585</color>";
4596 break;
4597 case 4:
4598 dirt_symbol = "<color_dark_gray>\u2587</color>";
4599 break;
4600 case 5:
4601 dirt_symbol = "<color_brown>\u2588</color>";
4602 break;
4603 default:
4604 dirt_symbol = "";
4605 }
4606 std::string damtext;
4607
4608 // for portions of string that have <color_ etc in them, this aims to truncate the whole string correctly
4609 unsigned int truncate_override = 0;
4610
4611 if( ( damage() != 0 || ( get_option<bool>( "ITEM_HEALTH_BAR" ) && is_armor() ) ) && !is_null() &&
4612 with_prefix ) {
4613 damtext = durability_indicator();
4614 if( get_option<bool>( "ITEM_HEALTH_BAR" ) ) {
4615 // get the utf8 width of the tags
4616 truncate_override = utf8_width( damtext, false ) - utf8_width( damtext, true );
4617 }
4618 }
4619 if( !faults.empty() ) {
4620 bool silent = true;
4621 for( const auto &fault : faults ) {
4622 if( !fault->has_flag( flag_SILENT ) ) {
4623 silent = false;
4624 break;
4625 }
4626 }
4627 if( silent ) {
4628 damtext.insert( 0, dirt_symbol );
4629 } else {
4630 damtext.insert( 0, _( "faulty " ) + dirt_symbol );
4631 }
4632 }
4633
4634 std::string vehtext;
4635 if( is_engine() && engine_displacement() > 0 ) {
4636 vehtext = string_format( pgettext( "vehicle adjective", "%2.1fL " ),
4637 engine_displacement() / 100.0f );
4638
4639 } else if( is_wheel() && type->wheel->diameter > 0 ) {
4640 vehtext = string_format( pgettext( "vehicle adjective", "%d\" " ), type->wheel->diameter );
4641 }
4642
4643 std::string burntext;
4644 if( with_prefix && !made_of( LIQUID ) ) {
4645 if( volume() >= 1_liter && burnt * 125_ml >= volume() ) {
4646 burntext = pgettext( "burnt adjective", "badly burnt " );
4647 } else if( burnt > 0 ) {
4648 burntext = pgettext( "burnt adjective", "burnt " );
4649 }
4650 }
4651
4652 std::string maintext;
4653 if( is_corpse() || typeId() == itype_blood || item_vars.find( "name" ) != item_vars.end() ) {
4654 maintext = type_name( quantity );
4655 } else if( is_gun() || is_tool() || is_magazine() ) {
4656 int amt = 0;
4657 maintext = label( quantity );
4658 for( const item *mod : is_gun() ? gunmods() : toolmods() ) {
4659 if( !type->gun || !type->gun->built_in_mods.count( mod->typeId() ) ) {
4660 amt++;
4661 }
4662 }
4663 if( amt ) {
4664 maintext += string_format( "+%d", amt );
4665 }
4666 } else if( is_armor() && has_clothing_mod() ) {
4667 maintext = label( quantity ) + "+1";
4668 } else if( is_craft() ) {
4669 maintext = string_format( _( "in progress %s" ), craft_data_->making->result_name() );
4670 if( charges > 1 ) {
4671 maintext += string_format( " (%d)", charges );
4672 }
4673 const int percent_progress = item_counter / 100000;
4674 maintext += string_format( " (%d%%)", percent_progress );
4675 } else if( contents.num_item_stacks() == 1 ) {
4676 const item &contents_item = contents.front();
4677 const unsigned contents_count =
4678 ( ( contents_item.made_of( LIQUID ) || contents_item.is_food() ) &&
4679 contents_item.charges > 1 )
4680 ? contents_item.charges
4681 : quantity;
4682 maintext = string_format( pgettext( "item name", "%2$s (%1$s)" ), label( quantity ),
4683 contents_item.tname( contents_count, with_prefix ) );
4684 } else if( !contents.empty() ) {
4685 maintext = string_format( vpgettext( "item name",
4686 //~ %1$s: item name, %2$zd: content size
4687 "%1$s with %2$zd item",
4688 "%1$s with %2$zd items", contents.num_item_stacks() ),
4689 label( quantity ), contents.num_item_stacks() );
4690 } else {
4691 maintext = label( quantity );
4692 }
4693
4694 avatar &you = get_avatar();
4695 std::string tagtext;
4696 if( is_food() ) {
4698 tagtext += _( " (poisonous)" );
4699 } else if( has_flag( flag_HIDDEN_HALLU ) && you.get_skill_level( skill_survival ) >= 5 ) {
4700 tagtext += _( " (hallucinogenic)" );
4701 }
4702 }
4703 if( is_book() ) {
4704 if( !you.has_identified( typeId() ) ) {
4705 tagtext += _( " (unread)" );
4706 }
4707 }
4708 if( has_var( "bionics_scanned_by" ) && has_flag( flag_CBM_SCANNED ) ) {
4709 tagtext += _( " (bionic detected)" );
4710 }
4711 if( has_flag( flag_ETHEREAL_ITEM ) ) {
4712 tagtext += string_format( _( " (%s turns)" ), get_var( "ethereal" ) );
4713 } else if( goes_bad() || is_food() ) {
4714 if( has_own_flag( "DIRTY" ) ) {
4715 tagtext += _( " (dirty)" );
4716 } else if( rotten() ) {
4717 tagtext += _( " (rotten)" );
4718 } else if( is_going_bad() ) {
4719 tagtext += _( " (old)" );
4720 } else if( is_fresh() ) {
4721 tagtext += _( " (fresh)" );
4722 }
4723 if( has_flag( flag_COLD ) ) {
4724 tagtext += _( " (cold)" );
4725 } else if( has_flag( flag_VERY_COLD ) ) {
4726 tagtext += _( " (very cold)" );
4727 }
4728 }
4729
4730 const sizing sizing_level = get_sizing( you, get_encumber( you ) != 0 );
4731
4732 if( sizing_level == sizing::human_sized_small_char ) {
4733 tagtext += _( " (too big)" );
4734 } else if( sizing_level == sizing::big_sized_small_char ) {
4735 tagtext += _( " (huge!)" );
4736 } else if( sizing_level == sizing::human_sized_big_char ||
4737 sizing_level == sizing::small_sized_human_char ) {
4738 tagtext += _( " (too small)" );
4739 } else if( sizing_level == sizing::small_sized_big_char ) {
4740 tagtext += _( " (tiny!)" );
4741 } else if( !has_flag( flag_FIT ) && has_flag( flag_VARSIZE ) ) {
4742 tagtext += _( " (poor fit)" );
4743 }
4744
4745 if( is_filthy() ) {
4746 tagtext += _( " (filthy)" );
4747 }
4749 tagtext += _( " (sterile)" );
4750 }
4751
4752 if( is_tool() && has_flag( flag_USE_UPS ) && !has_flag( flag_NAT_UPS ) ) {
4753 tagtext += _( " (UPS)" );
4754 }
4755 if( is_tool() && has_flag( flag_HEATS_FOOD ) ) {
4756 tagtext += _( " (heats)" );
4757 }
4758
4759 if( has_var( "NANOFAB_ITEM_ID" ) ) {
4760 tagtext += string_format( " (%s)", nname( itype_id( get_var( "NANOFAB_ITEM_ID" ) ) ) );
4761 }
4762
4763 if( has_flag( flag_RADIO_MOD ) ) {
4764 tagtext += _( " (radio:" );
4765 if( has_flag( flag_RADIOSIGNAL_1 ) ) {
4766 tagtext += pgettext( "The radio mod is associated with the [R]ed button.", "R)" );
4767 } else if( has_flag( flag_RADIOSIGNAL_2 ) ) {
4768 tagtext += pgettext( "The radio mod is associated with the [B]lue button.", "B)" );
4769 } else if( has_flag( flag_RADIOSIGNAL_3 ) ) {
4770 tagtext += pgettext( "The radio mod is associated with the [G]reen button.", "G)" );
4771 } else {
4772 debugmsg( "Why is the radio neither red, blue, nor green?" );
4773 tagtext += "?)";
4774 }
4775 }
4776
4777 if( has_flag( flag_WET ) ) {
4778 tagtext += _( " (wet)" );
4779 }
4780 if( already_used_by_player( you ) ) {
4781 tagtext += _( " (used)" );
4782 }
4784 tagtext += _( " (lit)" );
4785 } else if( has_flag( flag_IS_UPS ) && get_var( "cable" ) == "plugged_in" ) {
4786 tagtext += _( " (plugged in)" );
4787 } else if( active && !is_food() && !is_corpse() &&
4788 !string_ends_with( typeId().str(), "_on" ) ) {
4789 // Usually the items whose ids end in "_on" have the "active" or "on" string already contained
4790 // in their name, also food is active while it rots.
4791 tagtext += _( " (active)" );
4792 }
4793
4794 if( is_favorite ) {
4795 tagtext += _( " *" ); // Display asterisk for favorite items
4796 }
4797
4798 std::string modtext;
4800 modtext += _( "sawn-off " );
4801 }
4803 modtext += _( "pistol " );
4804 }
4805 if( has_flag( flag_DIAMOND ) ) {
4806 modtext += std::string( pgettext( "Adjective, as in diamond katana", "diamond" ) ) + " ";
4807 }
4808
4809 //~ This is a string to construct the item name as it is displayed. This format string has been added for maximum flexibility. The strings are: %1$s: Damage text (e.g. "bruised"). %2$s: burn adjectives (e.g. "burnt"). %3$s: tool modifier text (e.g. "atomic"). %4$s: vehicle part text (e.g. "3.8-Liter"). $5$s: main item text (e.g. "apple"). %6s: tags (e.g. "(wet) (poor fit)").
4810 std::string ret = string_format( _( "%1$s%2$s%3$s%4$s%5$s%6$s" ), damtext, burntext, modtext,
4811 vehtext, maintext, tagtext );
4812
4813 if( truncate != 0 ) {
4814 ret = utf8_truncate( ret, truncate + truncate_override );
4815 }
4816
4817 if( item_vars.find( "item_note" ) != item_vars.end() ) {
4818 //~ %s is an item name. This style is used to denote items with notes.
4819 return string_format( _( "*%s*" ), ret );
4820 } else {
4821 return ret;
4822 }
4823}
int utf8_width(const char *s, const bool ignore_tags)
std::string utf8_truncate(const std::string &s, size_t length)
bool has_flag(const std::string &flag) const
Definition: fault.h:61
bool is_wheel() const
Definition: item.cpp:6781
bool is_going_bad() const
an item is about to become rotten when shelf life has nearly elapsed
Definition: item.h:844
std::string durability_indicator(bool include_intact=false) const
Provides a prefix for the durability state of the item.
Definition: item.cpp:6342
std::string label(unsigned int quantity=0) const
Returns label from "item_label" itemvar and quantity.
Definition: item.cpp:9982
bool is_fresh() const
an item is fresh if it is capable of rotting but still has a long shelf life remaining
Definition: item.h:839
bool has_clothing_mod() const
Definition: item.cpp:10163
int engine_displacement() const
for combustion engines the displacement (cc)
Definition: item.cpp:4138
bool already_used_by_player(const player &p) const
Check whether the item has been marked (by calling mark_as_used_by_player) as used by this specific p...
Definition: item.cpp:8870
static const itype_id itype_blood("blood")
static const std::string flag_SILENT("SILENT")
static const std::string flag_HEATS_FOOD("HEATS_FOOD")
static const itype_id itype_stock_small("stock_small")
static const std::string flag_NAT_UPS("NAT_UPS")
static const itype_id itype_barrel_small("barrel_small")
static const std::string flag_CBM_SCANNED("CBM_SCANNED")
bool string_ends_with(const std::string &s1, const std::string &s2)
Returns true if s1 ends with s2.
Struct used for storing labels (easier to json opposed to a std::map<point, std::string>)
Definition: vehicle.h:286
const char * vpgettext(const char *const context, const char *const msgid, const char *const msgid_plural, const size_t n)
@ silent
Definition: weather_type.h:56

References _, active, already_used_by_player(), big_sized_small_char, burnt, charges, contents, craft_data_, damage(), debugmsg, durability_indicator(), item_contents::empty(), engine_displacement(), fault_bionic_nonsterile, faults, flag_CBM_SCANNED(), flag_COLD(), flag_DIAMOND(), flag_ETHEREAL_ITEM(), flag_FIT(), flag_HEATS_FOOD(), flag_HIDDEN_HALLU(), flag_HIDDEN_POISON(), flag_IS_UPS(), flag_LITCIG(), flag_NAT_UPS(), flag_RADIO_MOD(), flag_RADIOSIGNAL_1(), flag_RADIOSIGNAL_2(), flag_RADIOSIGNAL_3(), flag_SILENT(), flag_USE_UPS(), flag_VARSIZE(), flag_VERY_COLD(), flag_WATER_EXTINGUISH(), flag_WET(), item_contents::front(), get_avatar(), get_encumber(), get_sizing(), Character::get_skill_level(), get_var(), goes_bad(), itype::gun, gunmod_find(), gunmods(), has_clothing_mod(), has_fault(), fault::has_flag(), has_flag(), avatar::has_identified(), has_own_flag(), has_var(), human_sized_big_char, human_sized_small_char, is_armor(), is_bionic(), is_book(), is_corpse(), is_craft(), is_engine(), is_favorite, is_filthy(), is_food(), is_fresh(), is_going_bad(), is_gun(), is_magazine(), is_null(), is_tool(), is_wheel(), item_counter, item_vars, itype_barrel_small, itype_blood, itype_id, itype_stock_small, label(), LIQUID, made_of(), nname(), item_contents::num_item_stacks(), pgettext(), cata::hash64_detail::ret, rotten(), silent, skill_survival, small_sized_big_char, small_sized_human_char, string_ends_with(), string_format(), tname(), toolmods(), type, type_name(), typeId(), utf8_truncate(), utf8_width(), volume(), vpgettext(), and itype::wheel.

Referenced by Character::absorb_hit(), advanced_inventory::action_examine(), monexamine::add_armor(), game::add_artifact_dreams(), add_disassemblables(), MapgenRemovePartHandler::add_item_or_charges(), advanced_inventory_pane::add_items_from_area(), auto_pickup::player_settings::add_rule(), add_salvagables(), npc::alt_attack(), ammo_consume(), apply_lock_picking_tool(), apply_prying_tool(), Character::armor_absorb(), iuse::artifact(), inventory::assign_empty_invlet(), mattack::bio_op_disarm(), talk_function::bionic_remove(), Character::block_hit(), Character::block_ranged_hit(), iuse::blood_draw(), iuse::burrow(), activity_handlers::butcher_finish(), camp_car_description(), use_function::can_call(), npc::can_read(), repair_item_actor::can_repair_target(), Character::can_unwield(), Character::can_use(), Character::can_wear(), Character::can_wield(), iuse::capture_monster_act(), iuse::capture_monster_veh(), Character::change_side(), charges_per_volume(), iuse::chew(), iuse::coin_flip(), colorized_item_name(), game_menus::inv::compare(), crafting::complete_disassemble(), npc::confident_gun_mode_range(), Character::consume(), Character::consume_item(), iuse::contacts(), game_menus::inv::container_for(), iuse::craft(), auto_pickup::rule_list::create_rule(), iuse::crowbar(), salvage_actor::cut_up(), damage_item(), deactivate(), item_location::impl::item_in_container::describe(), iexamine::dimensional_portal(), iuse::directional_hologram(), display_money(), display_name(), iuse::dive_tank(), npc::do_reload(), draw_bionics_titlebar(), npc::drop_items(), drop_on_map(), drop_or_embed_projectile(), avatar_action::eat(), Character::eat(), iuse::ehandcuffs(), iuse::einktabletpc(), explosion_handler::emp_blast(), npc::execute_action(), Character::extended_description(), iuse::eyedrops(), Character::feed_furnace_with(), fetch_activity(), activity_handlers::fill_liquid_do_turn(), fill_with(), final_info(), npc::find_item(), heal_actor::finish_using(), ranged::fire_gun(), avatar_action::fire_wielded_weapon(), iuse::firecracker_act(), iexamine::fireplace(), iuse::fishing_rod(), iuse::flumed(), iuse::flusleep(), character_funcs::fmt_wielded_weapon(), Character::fuel_bionic_with(), iexamine::fvat_empty(), iexamine::fvat_full(), activity_handlers::game_do_turn(), iuse::gasmask(), generic_multi_activity_do(), avatar::get_book_reader(), get_continue_reqs(), get_encumber_when_containing(), get_making(), get_next_failure_point(), get_owner_name(), get_property_int64_t(), get_remaining_capacity_for_liquid(), vehicle::get_targeting_npc(), talk_function::give_equipment(), monexamine::give_items_to(), iuse::granade_act(), iuse::gun_repair(), avatar_funcs::gunmod_add(), activity_handlers::gunmod_add_finish(), avatar_funcs::gunmod_remove(), ranged::gunmode_checks_common(), ranged::gunmode_checks_weapon(), iuse::hand_crank(), repair_item_actor::handle_components(), handle_craft_failure(), ranged::handle_gun_damage(), liquid_handler::handle_liquid(), Character::handle_melee_wear(), handle_problematic_pickup(), Character::has_enough_charges(), auto_pickup::player_settings::has_rule(), npc::heal_self(), Character::i_add_to_container(), Character::i_rem(), ideal_ranged_dps(), iuse_transform::info(), info(), Character::invoke_item(), avatar::invoke_item(), advanced_inventory_pane::is_filtered(), Character::item_reload_cost(), npc::item_whitelisted(), iuse::jackhammer(), iexamine::keg(), game::list_items(), aim_activity_actor::load_RAS_weapon(), iuse::magic_8_ball(), marloss_common(), iuse::marloss_seed(), character_martial_arts::martialart_use_message(), iuse::meditate(), iuse::melatonin_tablet(), Character::melee_special_effects(), activity_handlers::mend_item_finish(), iuse::mind_splicer(), mod_charges(), mod_last_rot_check(), Character::modify_morale(), iuse::molotov_lit(), npc::mug_player(), iuse::multicooker(), Character::mutation_effect(), npc_throw(), on_wield(), iuse::oxygen_bottle(), iuse::pack_item(), target_ui::panel_gun_info(), parse_tags(), petfood(), pick_one_up(), iuse::pickaxe(), iuse::play_game(), avatar_action::plthrow(), iuse::portable_game(), Character::pour_into(), iexamine::pour_into_keg(), npc::pretend_fire(), game::print_items_info(), game::process_artifact(), process_blackpowder_fouling(), process_extinguish(), map::process_fields_in_submap(), process_internal(), process_litcig(), process_tool(), ranged::prompt_select_default_ammo_for(), mattack::pull_metal_weapon(), put_into_vehicle(), item_reload_option::qty(), iuse::radio_mod(), iuse::radiocar(), character_funcs::rate_sleep_spot(), player::reduce_charges(), avatar_action::reload(), bandolier_actor::reload(), reload(), activity_handlers::reload_finish(), remove_radio_mod(), auto_pickup::player_settings::remove_rule(), repair_item_actor::repair(), activity_handlers::repair_item_finish(), iuse::robotcontrol(), map::rotten_item_spawn(), iuse::rpgdie(), examine_item_menu::run(), iuse::seed(), character_funcs::select_ammo(), talk_effect_fun_t::set_bulk_trade_accept(), talk_effect_fun_t::set_consume_item(), set_item_inventory(), set_item_map(), set_item_map_or_vehicle(), set_mtype(), set_next_failure_point(), talk_effect_fun_t::set_u_buy_item(), gun_actor::shoot(), trading_window::show_item_data(), sleep(), smash(), iuse::smoking(), iuse::solarpack(), holster_actor::store(), npc::stow_item(), Character::suffer_from_bad_bionics(), monexamine::take_items_from(), Character::takeoff(), iuse::talking_doll(), tname(), iuse::toggle_heats_food(), tool_info(), iuse::towel_common(), iexamine::tree_maple_tapped(), try_consume(), avatar_funcs::try_disarm_npc(), try_reject_mutagen(), avatar_funcs::try_steal_from_npc(), salvage_actor::try_to_cut_up(), target_ui::uitext_title(), iuse::unfold_generic(), avatar_funcs::unload_item(), iuse::unpack_item(), Character::unwield(), inventory_entry::update_cache(), iuse_transform::use(), countdown_actor::use(), explosion_iuse::use(), unfold_vehicle_iuse::use(), set_transform_iuse::use(), change_scent_iuse::use(), deploy_furn_actor::use(), reveal_map_actor::use(), firestarter_actor::use(), inscribe_actor::use(), holster_actor::use(), ammobelt_actor::use(), heal_actor::use(), place_trap_actor::use(), deploy_tent_actor::use(), saw_barrel_actor::use(), saw_stock_actor::use(), unpack_actor::use(), cast_spell_actor::use(), heal_actor::use_healing_item(), avatar_funcs::use_item(), npc::use_painkiller(), iuse::vibe(), activity_handlers::vibe_do_turn(), Character::wear_item(), iuse::weather_tool(), avatar::wield(), avatar_action::wield(), Character::will_eat(), wind_resist(), debug_menu::wishitem(), memorial_logger::write(), and iuse::xanax().

◆ tool_info()

void item::tool_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3102 of file item.cpp.

3104{
3105 if( !is_tool() ) {
3106 return;
3107 }
3108
3110 if( ammo_capacity() != 0 && parts->test( iteminfo_parts::TOOL_CHARGES ) ) {
3111 info.emplace_back( "TOOL", string_format( _( "<bold>Charges</bold>: %d" ),
3112 ammo_remaining() ) );
3113 }
3114
3115 if( !magazine_integral() ) {
3117 info.emplace_back( "TOOL", _( "Magazine: " ),
3118 string_format( "<stat>%s</stat>", magazine_current()->tname() ) );
3119 }
3120
3122 const std::set<itype_id> compat = magazine_compatible();
3123 info.emplace_back( "TOOL", _( "Compatible magazines: " ),
3124 enumerate_as_string( compat.begin(), compat.end(), []( const itype_id & id ) {
3125 return item::nname( id );
3126 } ) );
3127 }
3128 } else if( ammo_capacity() != 0 && parts->test( iteminfo_parts::TOOL_CAPACITY ) ) {
3129 std::string tmp;
3130 bool bionic_tool = has_flag( flag_USES_BIONIC_POWER );
3131 if( !ammo_types().empty() ) {
3132 //~ "%s" is ammunition type. This types can't be plural.
3133 tmp = vgettext( "Maximum <num> charge of %s.", "Maximum <num> charges of %s.",
3134 ammo_capacity() );
3135 tmp = string_format( tmp, enumerate_as_string( ammo_types().begin(),
3136 ammo_types().end(), []( const ammotype & at ) {
3137 return at->name();
3139
3140 // No need to display max charges, since charges are always equal to bionic power
3141 } else if( !bionic_tool ) {
3142 tmp = vgettext( "Maximum <num> charge.", "Maximum <num> charges.", ammo_capacity() );
3143 }
3144 if( !bionic_tool ) {
3145 info.emplace_back( "TOOL", "", tmp, iteminfo::no_flags, ammo_capacity() );
3146 }
3147 }
3148}

References _, ammo_capacity(), ammo_remaining(), ammo_types(), enumerate_as_string(), flag_USES_BIONIC_POWER(), has_flag(), info(), insert_separation_line(), is_tool(), magazine_compatible(), magazine_current(), magazine_integral(), ammunition_type::name(), iteminfo::no_flags, none, string_format(), iteminfo_query::test(), tname(), TOOL_CAPACITY, TOOL_CHARGES, TOOL_MAGAZINE_COMPATIBLE, TOOL_MAGAZINE_CURRENT, and vgettext().

Referenced by info().

◆ toolmods() [1/2]

std::vector< item * > item::toolmods ( )

Returns all toolmods currently attached to this item (always empty if item not a tool)

Definition at line 5475 of file item.cpp.

5476{
5477 std::vector<item *> res;
5478 if( is_tool() ) {
5479 for( item *e : contents.all_items_top() ) {
5480 if( e->is_toolmod() ) {
5481 res.push_back( e );
5482 }
5483 }
5484 }
5485 return res;
5486}

References item_contents::all_items_top(), contents, and is_tool().

Referenced by ammo_capacity(), ammo_data(), ammo_types(), contents_info(), has_flag(), magazine_compatible(), magazine_default(), magazine_integral(), iuse::remove_all_mods(), tname(), and iuse::toolmod_attach().

◆ toolmods() [2/2]

std::vector< const item * > item::toolmods ( ) const

Definition at line 5488 of file item.cpp.

5489{
5490 std::vector<const item *> res;
5491 if( is_tool() ) {
5492 for( const item *e : contents.all_items_top() ) {
5493 if( e->is_toolmod() ) {
5494 res.push_back( e );
5495 }
5496 }
5497 }
5498 return res;
5499}

References item_contents::all_items_top(), contents, and is_tool().

◆ type_name()

std::string item::type_name ( unsigned int  quantity = 1) const

Name of the item type (not the item), with proper plural.

This is only special when the item itself has a special name ("name" entry in item_tags) or is a named corpse. It's effectively the same as calling nname with the item type id. Use this when the actual item is not meant, for example "The shovel" instead of "Your shovel". Or "The jacket is too small", when it applies to all jackets, not just the one the character tried to wear).

Definition at line 9881 of file item.cpp.

9882{
9883 const auto iter = item_vars.find( "name" );
9884 std::string ret_name;
9885 if( typeId() == itype_blood ) {
9886 if( corpse == nullptr || corpse->id.is_null() ) {
9887 return vpgettext( "item name", "human blood", "human blood", quantity );
9888 } else {
9889 return string_format( vpgettext( "item name", "%s blood",
9890 "%s blood", quantity ),
9891 corpse->nname() );
9892 }
9893 } else if( iter != item_vars.end() ) {
9894 return iter->second;
9895 } else {
9896 ret_name = type->nname( quantity );
9897 }
9898
9899 // Apply conditional names, in order.
9900 for( const conditional_name &cname : type->conditional_names ) {
9901 // Lambda for recursively searching for a item ID among all components.
9902 std::function<bool ( std::list<item> )> component_id_contains =
9903 [&]( std::list<item> components ) {
9904 for( const item &component : components ) {
9905 if( component.typeId().str().find( cname.condition ) != std::string::npos ||
9906 component_id_contains( component.components ) ) {
9907 return true;
9908 }
9909 }
9910 return false;
9911 };
9912 switch( cname.type ) {
9914 if( has_flag( cname.condition ) ) {
9915 ret_name = string_format( cname.name.translated( quantity ), ret_name );
9916 }
9917 break;
9919 if( component_id_contains( components ) ) {
9920 ret_name = string_format( cname.name.translated( quantity ), ret_name );
9921 }
9922 break;
9924 break;
9925 }
9926 }
9927
9928 // Identify who this corpse belonged to, if applicable.
9929 if( corpse != nullptr && has_flag( flag_CORPSE ) ) {
9930 if( corpse_name.empty() ) {
9931 //~ %1$s: name of corpse with modifiers; %2$s: species name
9932 ret_name = string_format( pgettext( "corpse ownership qualifier", "%1$s of a %2$s" ),
9933 ret_name, corpse->nname() );
9934 } else {
9935 //~ %1$s: name of corpse with modifiers; %2$s: proper name; %3$s: species name
9936 ret_name = string_format( pgettext( "corpse ownership qualifier", "%1$s of %2$s, %3$s" ),
9937 ret_name, corpse_name, corpse->nname() );
9938 }
9939 }
9940
9941 return ret_name;
9942}
@ COMPONENT_ID
Definition: itype.h:778
@ FLAG
Definition: itype.h:777
@ num_condition_types
Definition: itype.h:779
std::string condition
Definition: itype.h:792
translation name
Definition: itype.h:795
condition_type type
Definition: itype.h:790
std::vector< conditional_name > conditional_names
Definition: itype.h:889

References COMPONENT_ID, components, conditional_name::condition, itype::conditional_names, corpse, corpse_name, FLAG, flag_CORPSE(), has_flag(), mtype::id, string_id< T >::is_null(), item_vars, itype_blood, conditional_name::name, itype::nname(), mtype::nname(), num_condition_types, pgettext(), string_format(), translation::translated(), type, conditional_name::type, typeId(), and vpgettext().

Referenced by advanced_inventory::action_examine(), Character::can_wear(), game_menus::inv::compare(), avatar::do_read(), talk_function::field_harvest(), activity_handlers::fill_liquid_do_turn(), npc::finish_read(), character_funcs::fmt_wielded_weapon(), trading_window::get_var_trade(), Character::is_snuggling(), inscribe_actor::item_inscription(), label(), game::list_items(), Character::pour_into(), avatar::read(), bandolier_actor::reload(), game_menus::inv::repair(), examine_item_menu::run(), trading_window::show_item_data(), skim_book_msg(), Character::suffer_from_schizophrenia(), tname(), consume_drug_iuse::use(), place_monster_iuse::use(), and bandolier_actor::use().

◆ typeId()

const itype_id & item::typeId ( ) const

return the unique identifier of the items underlying type

Definition at line 8375 of file item.cpp.

8376{
8377 return type ? type->get_id() : itype_id::NULL_ID();
8378}

References itype::get_id(), string_id< itype >::NULL_ID(), and type.

Referenced by computer_session::action_blood_anal(), computer_session::action_data_anal(), add_disassemblables(), inventory::add_item_by_items_type_cache(), map::add_item_or_charges(), add_rain_to_container(), item_pricing::adjust_values(), vehicle_part::ammo_current(), ammo_set(), amount_of_internal(), armor_fit_info(), inventory::assign_empty_invlet(), iexamine::autodoc(), basic_info(), iuse::bell(), mattack::bio_op_takedown(), book_info(), Character::can_fuel_bionic_with(), vehicle_part::can_reload(), bandolier_actor::can_store(), Character::can_use_heal_item(), Character::can_wear(), Character::can_wield(), color_in_inventory(), combat_info(), crafting::complete_disassemble(), Character::compute_nutrient_range(), prepared_item_consumption::consume(), vehicle_part::consume_energy(), consumption_event::consumption_event(), mattack::copbot(), map::create_burnproducts(), iuse::directional_antenna(), disassembly_info(), Character::dismount(), iuse::dive_tank(), avatar::do_read(), npc::do_reload(), anonymous_namespace{iexamine.cpp}::atm_menu::do_transfer_all_money(), editmap::draw_main_ui_overlay(), iuse::ecig(), iuse::ehandcuffs(), explosion_handler::emp_blast(), computer_session::failure_destroy_blood(), computer_session::failure_destroy_data(), farm_valid_seed(), fetch_activity(), talk_function::field_harvest(), talk_function::field_plant(), activity_handlers::fill_liquid_do_turn(), fill_with(), final_info(), character_funcs::find_ammo_helper(), iexamine::fireplace(), food_info(), Character::fuel_bionic_with(), Character::fun_for(), iexamine::fvat_empty(), iuse::geiger(), json_talk_topic::gen_responses(), generic_multi_activity_do(), Character::get_acquirable_energy(), inventory::get_binned_items(), Character::get_bionic_fueled_with(), character_funcs::get_book_fun_for(), read_inventory_preset::get_denial(), bionic_install_preset::get_failure_chance(), Character::get_overlay_ids(), disassemble_inventory_preset::get_recipe(), get_remaining_capacity_for_liquid(), json_item_substitution::get_substitution(), get_uncraft_components(), give_item_to(), mattack::grab(), iuse::granade_act(), Character::has_active_item(), inventory::has_enough_painkiller(), Character::i_add(), Character::i_add_to_container(), monster::init_from_item(), init_memory_card_with_random_stuff(), io(), advanced_inv_area::is_container_valid(), character_funcs::is_fun_to_read(), is_funnel_container(), is_gunmod_compatible(), read_inventory_preset::is_known(), is_null(), is_reloadable_helper(), ma_requirements::is_valid_character(), item(), Character::item_handling_cost(), iexamine::keg(), ma_style_callback::key(), aim_activity_actor::load_RAS_weapon(), iuse::lumber(), iuse::marloss(), iuse::marloss_gel(), iuse::marloss_seed(), to_cbc_migration::migration_required(), iuse::mind_splicer(), Item_modifier::modify(), advanced_inventory::move_content(), iuse::mp3(), iuse::mp3_on(), item_stack::only_item(), iuse::pack_cbm(), iuse::pack_item(), iexamine::pedestal_temple(), iexamine::pedestal_wyrm(), peek_related_recipe(), pick_usb(), avatar_action::plthrow(), iexamine::pour_into_keg(), process_extinguish(), process_litcig(), examine_item_menu::rate_action_disassemble(), examine_item_menu::rate_action_read(), avatar::read(), game_menus::inv::reassign_letter(), reload(), activity_handlers::reload_finish(), repair_item_actor::repair_recipe_difficulty(), mattack::riotbot(), iuse::rm13armor_off(), iuse::rm13armor_on(), advanced_inv_area::set_container(), talk_effect_fun_t::set_remove_item_with(), player_morale::set_worn(), iuse::smoking(), iuse::solarpack(), iuse::solarpack_off(), Character::suffer_from_bad_bionics(), Character::suffer_from_radiation(), iuse::talking_doll(), tname(), iuse::toolmod_attach(), toolweapon_off(), toolweapon_on(), iuse::towel_common(), npc_trading::transfer_items(), iexamine::tree_maple_tapped(), disassemble_activity_actor::try_start_single(), salvage_actor::try_to_cut_up(), character_funcs::try_wield_contents(), type_name(), iuse::unpack_item(), inventory::update_cache_with_item(), inventory::update_invlet(), unfold_vehicle_iuse::use(), musical_instrument_actor::use(), unpack_actor::use(), use_amount_internal(), map::use_amount_square(), Character::use_charges(), map::use_charges(), avatar_funcs::use_item(), vehicle::use_washing_machine(), npc::value(), vehicle_part::vehicle_part(), volume(), iuse::water_purifier(), martialart::weapon_valid(), Character::wear_item(), iuse::weather_tool(), avatar::wield(), npc::wield_better_weapon(), and wind_resist().

◆ units_remaining()

int item::units_remaining ( const Character ch,
int  limit = INT_MAX 
) const

How many units (ammo or charges) are remaining?

Parameters
chcharacter responsible for invoking the item
limitstop searching after this many units found
Note
also checks availability of UPS charges if applicable

Definition at line 8009 of file item.cpp.

8010{
8011 if( count_by_charges() ) {
8012 return std::min( static_cast<int>( charges ), limit );
8013 }
8014
8015 int res = ammo_remaining();
8016 if( res < limit && is_power_armor() ) {
8018 res += std::max( ch.charges_of( itype_UPS, limit - res ), ch.charges_of( itype_bio_armor,
8019 limit - res ) );
8020 } else if( character_funcs::can_interface_armor( ch ) ) {
8021 res += ch.charges_of( itype_bio_armor, limit - res );
8022 } else {
8023 res += ch.charges_of( itype_UPS, limit - res );
8024 }
8025 } else if( res < limit && has_flag( flag_USE_UPS ) ) {
8026 res += ch.charges_of( itype_UPS, limit - res );
8027 }
8028
8029 return std::min( static_cast<int>( res ), limit );
8030}
int charges_of(const itype_id &what, int limit=INT_MAX, const std::function< bool(const item &)> &filter=return_true< item >, std::function< void(int)> visitor=nullptr) const
Count maximum available charges from this instance and any contained items.
Definition: visitable.cpp:947

References ammo_remaining(), character_funcs::can_interface_armor(), charges, visitable< T >::charges_of(), count_by_charges(), flag_USE_UPS(), has_flag(), is_power_armor(), itype_bio_armor, and itype_UPS.

Referenced by iuse::portable_game(), units_sufficient(), iuse_transform::use(), and set_transform_iuse::use().

◆ units_sufficient()

bool item::units_sufficient ( const Character ch,
int  qty = -1 
) const

Check if item has sufficient units (ammo or charges) remaining.

Parameters
chCharacter to check (used if ammo is UPS charges)
qtyunits required, if unspecified use item default

Definition at line 8032 of file item.cpp.

8033{
8034 if( qty < 0 ) {
8035 qty = count_by_charges() ? 1 : ammo_required();
8036 }
8037
8038 return units_remaining( ch, qty ) == qty;
8039}
int units_remaining(const Character &ch, int limit=INT_MAX) const
How many units (ammo or charges) are remaining?
Definition: item.cpp:8009

References ammo_required(), count_by_charges(), and units_remaining().

Referenced by cauterize_actor::can_use(), iuse::gun_repair(), iuse::mp3(), iuse::multicooker(), iuse::noise_emitter_off(), iuse::radglove(), iuse::radio_off(), iuse::radiocontrol(), iuse::remoteveh(), activity_handlers::repair_item_finish(), iuse::robotcontrol(), iuse::shocktonfa_off(), iuse::shocktonfa_on(), iuse::talking_doll(), iuse::tazer(), toolweapon_off(), toolweapon_on(), iuse::vibe(), and iuse::water_purifier().

◆ unset_flag()

item & item::unset_flag ( const std::string &  flag)

◆ unset_flags()

void item::unset_flags ( )

Removes all item specific flags.

Definition at line 5314 of file item.cpp.

5315{
5316 item_tags.clear();
5317}

References item_tags.

Referenced by iuse::camera(), einkpc_download_memory_card(), and iuse::einktabletpc().

◆ update_clothing_mod_val()

void item::update_clothing_mod_val ( )

Definition at line 10195 of file item.cpp.

10196{
10198 float tmp = 0.0;
10199 for( const clothing_mod &cm : clothing_mods::get_all_with( type ) ) {
10200 if( has_own_flag( cm.flag ) ) {
10201 tmp += cm.get_mod_val( type, *this );
10202 }
10203 }
10205 }
10206}
clothing_mod_type
Definition: clothing_mod.h:16
const std::vector< clothing_mod > & get_all_with(clothing_mod_type type)
constexpr std::array< clothing_mod_type, 9 > all_clothing_mod_types
Definition: clothing_mod.h:63

References clothing_mods::all_clothing_mod_types, clothing_mods::get_all_with(), anonymous_namespace{item.cpp}::get_clothing_mod_val_key(), has_own_flag(), set_var(), and type.

Referenced by sew_advanced_actor::use().

◆ use_amount()

bool item::use_amount ( const itype_id it,
int &  quantity,
std::list< item > &  used,
const std::function< bool(const item &)> &  filter = return_true<item> 
)

Consume a specific amount of items of a specific type.

This includes this item, and any of its contents (recursively).

See also
item::use_charges - this is similar for items, not charges.
Parameters
itType of consumable item.
quantityHow much to consumed.
usedOn success all consumed items will be stored here.
filterMust return true for use to occur.

Definition at line 8513 of file item.cpp.

8515{
8516 // Remember quantity so that we can unseal self
8517 int old_quantity = quantity;
8518 std::vector<item *> removed_items;
8519 // First, check contents
8521 [&]( item * a ) {
8522 // visit_items checks the item itself first. we want to do its contents first.
8523 if( a == this ) {
8524 return VisitResponse::NEXT;
8525 }
8526 if( a->use_amount_internal( it, quantity, used, filter ) ) {
8527 removed_items.emplace_back( a );
8528 return VisitResponse::SKIP;
8529 }
8530 return VisitResponse::NEXT;
8531 } );
8532
8533 for( item *remove : removed_items ) {
8534 remove_item( *remove );
8535 }
8536
8537 if( quantity != old_quantity ) {
8539 }
8540 return use_amount_internal( it, quantity, used, filter );
8541}
bool use_amount_internal(const itype_id &it, int &quantity, std::list< item > &used, const std::function< bool(const item &)> &filter=return_true< item >)
Definition: item.cpp:8543
constexpr double a
Definition: magic.cpp:1030

References a, NEXT, on_contents_changed(), visitable< item >::remove_item(), use_amount_internal(), and visitable< item >::visit_items().

◆ use_amount_internal()

bool item::use_amount_internal ( const itype_id it,
int &  quantity,
std::list< item > &  used,
const std::function< bool(const item &)> &  filter = return_true<item> 
)
private

Definition at line 8543 of file item.cpp.

8545{
8546 if( typeId() == it && quantity > 0 && filter( *this ) ) {
8547 used.push_back( *this );
8548 quantity--;
8549 return true;
8550 } else {
8551 return false;
8552 }
8553}

References typeId().

Referenced by use_amount().

◆ use_charges()

bool item::use_charges ( const itype_id what,
int &  qty,
std::list< item > &  used,
const tripoint pos,
const std::function< bool(const item &)> &  filter = return_true<item> 
)

Consumes specified charges (or fewer) from this and any contained items.

Parameters
whatspecific type of charge required, e.g. 'battery'
qtymaximum charges to consume. On return set to number of charges not found (or zero)
usedfilled with duplicates of each item that provided consumed charges
posposition at which the charges are being consumed
filterMust return true for use to occur.
Returns
true if this item should be deleted (count-by-charges items with no remaining charges)

Definition at line 8633 of file item.cpp.

8635{
8636 std::vector<item *> del;
8637
8638 visit_items( [&what, &qty, &used, &pos, &del, &filter]( item * e, item * parent ) {
8639 if( qty == 0 ) {
8640 // found sufficient charges
8641 return VisitResponse::ABORT;
8642 }
8643
8644 if( !filter( *e ) ) {
8645 return VisitResponse::NEXT;
8646 }
8647
8648 if( e->is_tool() ) {
8649 if( e->typeId() == what ) {
8650 int n = std::min( e->ammo_remaining(), qty );
8651 qty -= n;
8652
8653 used.push_back( item( *e ).ammo_set( e->ammo_current(), n ) );
8654 e->ammo_consume( n, pos );
8655 }
8656 return VisitResponse::SKIP;
8657
8658 } else if( e->count_by_charges() ) {
8659 if( e->typeId() == what ) {
8660
8661 // if can supply excess charges split required off leaving remainder in-situ
8662 item obj = e->split( qty );
8663 if( parent ) {
8664 parent->on_contents_changed();
8665 }
8666 if( !obj.is_null() ) {
8667 used.push_back( obj );
8668 qty = 0;
8669 return VisitResponse::ABORT;
8670 }
8671
8672 qty -= e->charges;
8673 used.push_back( *e );
8674 del.push_back( e );
8675 }
8676 // items counted by charges are not themselves expected to be containers
8677 return VisitResponse::SKIP;
8678 }
8679
8680 // recurse through any nested containers
8681 return VisitResponse::NEXT;
8682 } );
8683
8684 bool destroy = false;
8685 for( item *e : del ) {
8686 if( e == this ) {
8687 destroy = true; // cannot remove ourselves...
8688 } else {
8689 remove_item( *e );
8690 }
8691 }
8692
8693 return destroy;
8694}

References ABORT, count_by_charges(), is_tool(), NEXT, SKIP, and visitable< item >::visit_items().

Referenced by Character::use_charges(), and use_charges_from_furn().

◆ validate_ownership()

void item::validate_ownership ( ) const

Definition at line 1295 of file item.cpp.

1296{
1297 if( !old_owner.is_null() && !g->faction_manager_ptr->get( old_owner, false ) ) {
1299 }
1300 if( !owner.is_null() && !g->faction_manager_ptr->get( owner, false ) ) {
1301 remove_owner();
1302 }
1303}
void remove_old_owner() const
Definition: item.h:2032
void remove_owner() const
Definition: item.h:2039

References g, string_id< T >::is_null(), old_owner, owner, remove_old_owner(), and remove_owner().

Referenced by get_old_owner(), and get_owner().

◆ volume()

units::volume item::volume ( bool  integral = false) const

Total volume of an item accounting for all contained/integrated items NOTE: Result is rounded up to next nearest milliliter when working with stackable (count_by_charges) items that have fractional volume per charge.

If trying to determine how many of an item can fit in a given space, charges_per_volume should be used instead.

Parameters
integralif true return effective volume if this item was integrated into another

Definition at line 5130 of file item.cpp.

5131{
5132 if( is_null() ) {
5133 return 0_ml;
5134 }
5135
5136 if( is_corpse() ) {
5137 return corpse_volume( corpse );
5138 }
5139
5140 if( is_craft() ) {
5141 units::volume ret = 0_ml;
5142 for( const item &it : components ) {
5143 ret += it.volume();
5144 }
5145 return ret;
5146 }
5147
5148 const int local_volume = get_var( "volume", -1 );
5150 if( local_volume >= 0 ) {
5151 ret = local_volume * units::legacy_volume_factor;
5152 } else if( integral ) {
5154 } else {
5155 ret = type->volume;
5156 }
5157
5158 if( count_by_charges() || made_of( LIQUID ) ) {
5160 ( charges );
5161 if( type->stack_size <= 0 ) {
5162 debugmsg( "Item type %s has invalid stack_size %d", typeId().str(), type->stack_size );
5163 ret = num;
5164 } else {
5165 ret = num / type->stack_size;
5166 if( num % type->stack_size != 0_ml ) {
5167 ret += 1_ml;
5168 }
5169 }
5170 }
5171
5172 // Non-rigid items add the volume of the content
5173 if( !type->rigid ) {
5175 }
5176
5177 // Some magazines sit (partly) flush with the item so add less extra volume
5178 if( magazine_current() != nullptr ) {
5179 ret += std::max( magazine_current()->volume() - type->magazine_well, 0_ml );
5180 }
5181
5182 if( is_gun() ) {
5183 for( const item *elem : gunmods() ) {
5184 ret += elem->volume( true );
5185 }
5186
5187 // TODO: implement stock_length property for guns
5189 // consider only the base size of the gun (without mods)
5190 ret -= ( type->volume / 3 );
5191 }
5192
5194 ret -= type->gun->barrel_length;
5195 }
5196 }
5197
5198 return ret;
5199}
static const std::string flag_COLLAPSIBLE_STOCK("COLLAPSIBLE_STOCK")
units::volume magazine_well
Volume above which the magazine starts to protrude from the item and add extra volume.
Definition: itype.h:997
units::volume integral_volume
Space consumed when integrated as part of another item (defaults to volume) CAUTION: value given is f...
Definition: itype.h:950

References charges, components, contents, corpse, corpse_volume(), count_by_charges(), debugmsg, flag_COLLAPSIBLE_STOCK(), get_var(), itype::gun, gunmod_find(), gunmods(), has_flag(), itype::integral_volume, is_corpse(), is_craft(), is_gun(), is_null(), item_contents::item_size_modifier(), itype_barrel_small, units::legacy_volume_factor, LIQUID, made_of(), magazine_current(), itype::magazine_well, num, cata::hash64_detail::ret, itype::rigid, itype::stack_size, type, typeId(), volume(), and itype::volume.

Referenced by activity_on_turn_move_loot(), map::add_item_or_charges(), ranged::aim_cap_from_volume(), attack_cost(), basic_info(), veh_interact::calc_overview(), holster_actor::can_holster(), charges_per_volume(), comestible_inventory_preset::comestible_inventory_preset(), vehicle_part::consume_energy(), salvage_actor::cut_up(), Character::deal_damage(), npc::drop_items(), drop_or_embed_projectile(), fetch_activity(), iexamine::fvat_empty(), Character::get_acquirable_energy(), get_encumber_when_containing(), ranged::get_weapon_dispersion(), monexamine::give_items_to(), repair_item_actor::handle_components(), Character::item_handling_cost(), mdeath::jabberwock(), iexamine::keg(), Character::melee_special_effects(), move_cost_cart(), move_cost_inv(), iexamine::nanofab(), npc_pickup_from_stack(), pickup::obtain_and_tokenize_items(), Character::on_dodge(), on_wield(), vehicle::operate_scoop(), pick_one_up(), pickup::pick_up(), iexamine::pour_into_keg(), Character::power_rating(), process_corpse(), iuse::radiocar(), ready_to_revive(), pickup::reorder_for_dropping(), item_pricing::set_values(), npc::shop_restock(), smash(), holster_actor::store(), npc::stow_item(), stumble(), Character::takeoff(), ranged::throw_item(), Character::throw_range(), ranged::throwing_dispersion(), salvage_actor::time_to_cut_up(), tname(), salvage_actor::try_to_cut_up(), Character::update_bodytemp(), salvage_actor::valid_to_cut_up(), volume(), inventory::volume_without(), and wash_items().

◆ weight()

units::mass item::weight ( bool  include_contents = true,
bool  integral = false 
) const

Definition at line 4984 of file item.cpp.

4985{
4986 if( is_null() ) {
4987 return 0_gram;
4988 }
4989
4990 // Items that don't drop aren't really there, they're items just for ease of implementation
4991 if( has_flag( flag_NO_DROP ) ) {
4992 return 0_gram;
4993 }
4994
4995 if( is_craft() ) {
4996 units::mass ret = 0_gram;
4997 for( const item &it : components ) {
4998 ret += it.weight();
4999 }
5000 return ret;
5001 }
5002
5004 std::string local_str_mass = integral ? get_var( "integral_weight" ) : get_var( "weight" );
5005 if( local_str_mass.empty() ) {
5006 ret = integral ? type->integral_weight : type->weight;
5007 } else {
5008 ret = units::from_milligram( std::stoll( local_str_mass ) );
5009 }
5010
5011 if( has_flag( flag_REDUCED_WEIGHT ) ) {
5012 ret *= 0.75;
5013 }
5014
5015 // if this is a gun apply all of its gunmods' weight multipliers
5016 if( is_gun() ) {
5017 for( const item *mod : gunmods() ) {
5018 ret *= mod->type->gunmod->weight_multiplier;
5019 }
5020 }
5021
5022 if( count_by_charges() ) {
5023 ret *= charges;
5024
5025 } else if( is_corpse() ) {
5026 assert( corpse ); // To appease static analysis
5027 ret = corpse->weight;
5029 ret *= 0.75;
5030 }
5031 if( has_flag( flag_QUARTERED ) ) {
5032 ret /= 4;
5033 }
5034 if( has_flag( flag_GIBBED ) ) {
5035 ret *= 0.85;
5036 }
5037 if( has_flag( flag_SKINNED ) ) {
5038 ret *= 0.85;
5039 }
5040
5041 } else if( magazine_integral() && !is_magazine() ) {
5042 if( ammo_current() == itype_plut_cell ) {
5043 units::mass w = ( *ammo_types().begin() )->default_ammotype()->weight;
5045 } else if( ammo_data() ) {
5047 }
5048 }
5049
5050 // if this is an ammo belt add the weight of any implicitly contained linkages
5051 if( is_magazine() && type->magazine->linkage ) {
5052 item links( *type->magazine->linkage );
5053 links.charges = ammo_remaining();
5054 ret += links.weight();
5055 }
5056
5057 // reduce weight for sawn-off weapons capped to the apportioned weight of the barrel
5059 const units::volume b = type->gun->barrel_length;
5060 const units::mass max_barrel_weight = units::from_gram( to_milliliter( b ) );
5061 const units::mass barrel_weight = units::from_gram( b.value() * type->weight.value() /
5062 type->volume.value() );
5063 ret -= std::min( max_barrel_weight, barrel_weight );
5064 }
5065
5066 if( is_gun() ) {
5067 for( const item *elem : gunmods() ) {
5068 ret += elem->weight( true, true );
5069 }
5070 if( !magazine_integral() && magazine_current() ) {
5071 ret += std::max( magazine_current()->weight(), 0_gram );
5072 }
5073 } else if( include_contents ) {
5075 }
5076
5077 return ret;
5078}
units::mass item_weight_modifier() const
static const std::string flag_NO_DROP("NO_DROP")
static const std::string flag_REDUCED_WEIGHT("REDUCED_WEIGHT")
static const itype_id itype_plut_cell("plut_cell")
constexpr double b
Definition: magic.cpp:1031
constexpr value_type to_milliliter(const quantity< value_type, volume_in_milliliter_tag > &v)
Definition: units_volume.h:38
constexpr quantity< value_type, mass_in_milligram_tag > from_milligram(const value_type v)
Definition: units_mass.h:34
constexpr quantity< value_type, mass_in_milligram_tag > from_gram(const value_type v)
Definition: units_mass.h:41
units::mass integral_weight
Weight difference with the part it replaces for mods.
Definition: itype.h:938
units::mass weight
Definition: mtype.h:264

References ammo_current(), ammo_data(), ammo_remaining(), ammo_types(), b, charges, components, contents, corpse, count_by_charges(), flag_FIELD_DRESS(), flag_FIELD_DRESS_FAILED(), flag_GIBBED(), flag_NO_DROP(), flag_QUARTERED(), flag_REDUCED_WEIGHT(), flag_SKINNED(), units::from_gram(), units::from_milligram(), get_var(), itype::gun, gunmod_find(), gunmods(), has_flag(), itype::integral_weight, is_corpse(), is_craft(), is_gun(), is_magazine(), is_null(), item_contents::item_weight_modifier(), itype_barrel_small, itype_plut_cell, itype::magazine, magazine_current(), magazine_integral(), PLUTONIUM_CHARGES, cata::hash64_detail::ret, units::to_milliliter(), type, units::quantity< V, U >::value(), itype::volume, weight(), itype::weight, and mtype::weight.

Referenced by monexamine::add_armor(), attack_cost(), basic_info(), can_do_activity_there(), holster_actor::can_holster(), Character::can_pick_weight(), veh_interact::can_remove_part(), pickup::cost_to_move_item(), npc::drop_items(), fetch_activity(), funnel_charges_per_turn(), Character::get_acquirable_energy(), Character::get_weight(), monexamine::give_items_to(), is_two_handed(), lift_strength(), Character::melee_attack(), npc_pickup_from_stack(), pick_one_up(), pickup::pick_up(), advanced_inventory::query_charges(), iuse::radiocar(), item_pricing::set_values(), smash(), holster_actor::store(), stumble(), ranged::throw_item(), Character::throw_range(), ranged::throwing_dispersion(), trap::triggered_by_item(), veh_interact::update_part_requirements(), weight(), Character::weight_carried_reduced_by(), and inventory::weight_without().

◆ wheel_area()

int item::wheel_area ( ) const

Returns the total area of this wheel or 0 if it isn't one.

Definition at line 6837 of file item.cpp.

6838{
6839 return is_wheel() ? type->wheel->diameter * type->wheel->width : 0;
6840}

References is_wheel(), type, and itype::wheel.

◆ will_explode_in_fire()

bool item::will_explode_in_fire ( ) const

Definition at line 8751 of file item.cpp.

8752{
8753 if( type->explode_in_fire ) {
8754 return true;
8755 }
8756
8757 if( type->ammo && ( type->ammo->special_cookoff || type->ammo->cookoff ) ) {
8758 return true;
8759 }
8760
8761 // Most containers do nothing to protect the contents from fire
8762 if( !is_magazine() || !type->magazine->protects_contents ) {
8763 return has_item_with( [&]( const item & it ) {
8764 return this != &it && it.will_explode_in_fire();
8765 } );
8766 }
8767
8768 return false;
8769}
bool will_explode_in_fire() const
Definition: item.cpp:8751
bool explode_in_fire
Definition: itype.h:918

References itype::ammo, itype::explode_in_fire, visitable< item >::has_item_with(), is_magazine(), itype::magazine, type, and will_explode_in_fire().

Referenced by will_explode_in_fire().

◆ wind_resist()

int item::wind_resist ( ) const

How resistant clothes made of this material are to wind (0-100)

Definition at line 6806 of file item.cpp.

6807{
6808 std::vector<const material_type *> materials = made_of_types();
6809 if( materials.empty() ) {
6810 debugmsg( "Called item::wind_resist on an item (%s [%s]) made of nothing!", tname(), typeId() );
6811 return 99;
6812 }
6813
6814 int best = -1;
6815 for( const material_type *mat : materials ) {
6816 std::optional<int> resistance = mat->wind_resist();
6817 if( resistance && *resistance > best ) {
6818 best = *resistance;
6819 }
6820 }
6821
6822 // Default to 99% effective
6823 if( best == -1 ) {
6824 return 99;
6825 }
6826
6827 return best;
6828}

References debugmsg, made_of_types(), tname(), and typeId().

Referenced by wind_resistance_from_item_list().

Member Data Documentation

◆ activated_by

safe_reference<Character> item::activated_by

Definition at line 2248 of file item.h.

Referenced by detonate(), itype::invoke(), and explosion_iuse::use().

◆ active

bool item::active = false

Definition at line 2247 of file item.h.

Referenced by activate(), Character::activate_bionic(), map::add_item(), npc::alt_attack(), iexamine::autodoc(), basic_info(), burn(), iuse::c4(), iuse::cable_attach(), holster_actor::can_holster(), countdown_actor::can_use(), check_litcig(), color_in_inventory(), Character::consume_remote_fuel(), deactivate(), mdeath::detonate(), iuse::dive_tank(), iuse::ehandcuffs(), iuse::einktabletpc(), explosion_handler::emp_blast(), Character::find_remote_fuel(), iuse::firecracker(), iuse::firecracker_pack(), iuse::fish_trap(), iuse::gasmask(), iuse::geiger(), iuse::granade(), Character::has_active_item(), io(), enchantment::is_active(), item(), mattack::kamikaze(), make_gun_projectile(), activity_handlers::make_zlave_finish(), iuse::mininuke(), iuse::molotov_lit(), iuse::mp3(), iuse::mp3_on(), iuse::multicooker(), needs_processing(), iuse::noise_emitter_off(), iuse::noise_emitter_on(), on_takeoff(), on_wear(), iuse::pack_item(), process_extinguish(), process_internal(), process_litcig(), process_tool(), process_UPS(), process_wet(), vehicle_part::properties_to_item(), iuse::radio_off(), iuse::radio_on(), iuse::radiocar(), iuse::radiocaron(), iuse::radiocontrol(), read(), iuse::remoteveh(), reset_cable(), mattack::riotbot(), iuse::rm13armor_off(), iuse::rm13armor_on(), iuse::shocktonfa_off(), iuse::shocktonfa_on(), sleep(), iuse::smoking(), iuse::solarpack_off(), stacks_with(), holster_actor::store(), ranged::throw_item(), iuse::throwable_extinguisher_act(), tname(), toolweapon_off(), toolweapon_on(), iuse::tow_attach(), iuse::towel_common(), avatar_funcs::unload_item(), iuse::unpack_item(), iuse_transform::use(), countdown_actor::use(), fireweapon_off_actor::use(), musical_instrument_actor::use(), and npc::value().

◆ anchor

safe_reference_anchor item::anchor
private

Definition at line 2179 of file item.h.

Referenced by get_safe_reference().

◆ bday

time_point item::bday
private

The time the item was created.

Definition at line 2237 of file item.h.

Referenced by birthday(), io(), item(), legacy_fast_forward_time(), and set_birthday().

◆ burnt

int item::burnt = 0

◆ charges

int item::charges

Definition at line 2209 of file item.h.

Referenced by iuse::acidbomb_act(), act_vehicle_siphon(), Character::activate_bionic(), activity_on_turn_wear(), vehicle::add_charges(), vehicle::add_item(), map::add_item_or_charges(), avatar_funcs::add_or_drop_with_msg(), add_rain_to_container(), ammo_consume(), vehicle_part::ammo_consume(), ammo_remaining(), vehicle_part::ammo_remaining(), ammo_set(), ammo_unset(), item_stack::amount_can_fit(), jmapgen_liquid_item::apply(), are_requirements_nearby(), iuse::arrow_flammable(), basic_info(), burn(), iuse::c4(), iuse::can_goo(), bandolier_actor::can_store(), fireweapon_off_actor::can_use(), manualnoise_actor::can_use(), comestible_inventory_preset::comestible_inventory_preset(), complete_craft(), crafting::complete_disassemble(), veh_interact::complete_vehicle(), Character::consume_charges(), vehicle_part::consume_energy(), Character::consume_item(), liquid_handler::consume_liquid(), Character::consume_med(), game_menus::inv::container_for(), count(), activity_handlers::craft_do_turn(), recipe::create_byproducts(), recipe::create_result(), recipe::create_results(), detonate(), mdeath::detonate(), display_name(), iuse::dive_tank(), anonymous_namespace{iexamine.cpp}::atm_menu::do_purchase_card(), npc::do_reload(), veh_interact::do_siphon(), anonymous_namespace{iexamine.cpp}::atm_menu::do_transfer_all_money(), move_items_activity_actor::do_turn(), throw_activity_actor::do_turn(), anonymous_namespace{iexamine.cpp}::atm_menu::do_withdraw_money(), map::draw_lab(), iuse::ehandcuffs(), explosion_handler::emp_blast(), iuse::eyedrops(), farm_action(), Character::feed_furnace_with(), fetch_activity(), talk_function::field_harvest(), activity_handlers::fill_liquid_do_turn(), fill_with(), final_info(), wash_activity_actor::finish(), heal_actor::finish_using(), iuse::firecracker(), iuse::firecracker_act(), iuse::firecracker_pack(), iuse::firecracker_pack_act(), iuse::fish_trap(), character_funcs::fmt_wielded_weapon(), food_info(), for_each_item_in_both(), inventory::form_from_map(), Character::fuel_bionic_with(), funnel_charges_per_turn(), iexamine::fvat_empty(), iexamine::fvat_full(), iuse::gasmask(), Character::get_acquirable_energy(), activity_handlers::repair_activity_hack::anonymous_namespace{activity_handlers.cpp}::get_fake_tool(), iexamine::get_harvest_items(), liquid_handler::get_liquid_target(), get_remaining_capacity_for_liquid(), inventory_entry::get_selected_charges(), json_item_substitution::get_substitution(), monexamine::give_items_to(), iuse::granade(), iuse::granade_act(), iuse::grenade_inc_act(), hackveh(), liquid_handler::handle_all_liquid(), liquid_handler::handle_liquid_from_container(), pickup::handle_spillable_contents(), has_infinite_charges(), Character::i_add_to_container(), io(), item(), Character::item_reload_cost(), iexamine::keg(), med_info(), merge_charges(), Item_factory::migrate_item(), activity_handlers::milk_finish(), iuse::mininuke(), mod_charges(), mod_damage(), Item_modifier::modify(), iuse::molotov_lit(), advanced_inventory::move_all_items(), advanced_inventory::move_content(), move_item(), iuse::multicooker(), npc_throw(), vehicle::operate_planter(), operator<(), parse_tags(), iexamine::pay_gas(), liquid_handler::perform_liquid_transfer(), pick_one_up(), pickup::pick_up(), map::place_gas_pump(), map::place_toilet(), Character::pour_into(), iexamine::pour_into_keg(), advanced_inventory::print_items(), game::process_artifact(), process_cable(), Character::process_items(), relic_funcs::process_recharge_entry(), map::produce_sap(), vehicle_part::properties_to_item(), item_reload_option::qty(), advanced_inventory::query_charges(), player::reduce_charges(), bandolier_actor::reload(), reload(), remove_ammo(), reset_cable(), mattack::riotbot(), talk_effect_fun_t::set_bulk_trade_accept(), set_countdown(), iexamine::sign(), character_funcs::siphon(), smoker_activate(), map::spawn_an_item(), spell_effect::spawn_ethereal_item(), split(), stacks_with(), Character::suffer_from_bad_bionics(), iuse::tazer2(), Character::throw_range(), iuse::throwable_extinguisher_act(), ranged::throwing_dispersion(), tname(), npc_trading::trade(), npc_trading::transfer_items(), iexamine::tree_maple_tapped(), try_consume(), try_fuel_fire(), units_remaining(), avatar_funcs::unload_item(), inventory::update_quality_cache(), explosion_iuse::use(), place_monster_iuse::use(), fireweapon_off_actor::use(), fireweapon_on_actor::use(), manualnoise_actor::use(), bandolier_actor::use(), emit_actor::use(), sew_advanced_actor::use(), basecamp::use_charges(), map::use_charges(), use_charges_from_furn(), iexamine::use_furn_fake_item(), volume(), iuse::water_purifier(), weight(), Character::weight_carried_reduced_by(), debug_menu::wishitem(), and memorial_logger::write().

◆ components

◆ contents

item_contents item::contents

Definition at line 2171 of file item.h.

Referenced by Character::absorb_hit(), act_vehicle_siphon(), computer_session::action_blood_anal(), computer_session::action_data_anal(), actualize_rot(), vehicle::add_item(), add_rain_to_container(), allow_crafting_component(), ammo_consume(), vehicle_part::ammo_consume(), vehicle_part::ammo_current(), ammo_data(), ammo_remaining(), vehicle_part::ammo_remaining(), vehicle_part::ammo_set(), ammo_unset(), vehicle_part::ammo_unset(), map::bash_items(), iuse::blood_draw(), activity_handlers::butcher_finish(), item_location::impl::item_in_container::calc_index(), veh_interact::calc_overview(), item_funcs::can_be_unloaded(), Character::can_consume(), can_holster(), bandolier_actor::can_store(), can_unload_liquid(), casings_handle(), complete_craft(), veh_interact::complete_vehicle(), Character::compute_nutrient_range(), Character::consume(), npc::consume_cbm_items(), vehicle_part::consume_energy(), contents_info(), contents_made_of(), salvage_actor::cut_up(), damage_item(), item_location::deserialize(), deserialize(), detonate(), display_name(), veh_interact::do_siphon(), avatar_action::eat(), empty_buckets(), computer_session::failure_destroy_blood(), computer_session::failure_destroy_data(), fill_with(), final_info(), character_funcs::find_ammo_helper(), character_funcs::fmt_wielded_weapon(), get_category(), Character::get_consumable_from(), get_contained(), get_encumber(), get_free_mod_locations(), liquid_handler::get_liquid_target(), get_quality(), get_remaining_capacity_for_liquid(), json_item_substitution::get_substitution(), trading_window::get_var_trade(), goes_bad_after_opening(), gunmods(), liquid_handler::handle_liquid_from_container(), Character::handle_melee_wear(), handle_problematic_pickup(), pickup::handle_spillable_contents(), has_effect_when_carried(), Character::i_add_to_container(), info(), is_ammo_container(), is_container_empty(), is_container_full(), advanced_inv_area::is_container_valid(), is_dangerous(), is_food_container(), is_funnel_container(), is_med_container(), is_reloadable_helper(), item_has_uses_recursive(), Character::item_reload_cost(), magazine_current(), item_location::impl::item_in_container::make_dirty(), Character::melee_special_effects(), Item_factory::migrate_item(), activity_handlers::mind_splicer_finish(), advanced_inventory::move_content(), iuse::multicooker(), needs_processing(), on_pickup(), operator<(), peek_related_recipe(), put_in(), item_reload_option::qty(), qualities_info(), iuse::radiocar(), avatar_action::reload(), bandolier_actor::reload(), reload(), item_contents::remove_internal(), visitable< T >::remove_items_with(), character_funcs::select_ammo(), serialize(), advanced_inv_area::set_container(), map::smash_items(), spill_contents(), spoilage_sort_order(), stacks_with(), tname(), toolmods(), iexamine::tree_maple_tapped(), try_consume(), salvage_actor::try_to_cut_up(), character_funcs::try_wield_contents(), avatar_funcs::unload_item(), item_location::impl::item_in_container::unpack(), holster_actor::use(), bandolier_actor::use(), salvage_actor::valid_to_cut_up(), visit_internal(), volume(), iuse::water_purifier(), weight(), avatar::wield(), avatar_action::wield(), npc::wield_better_weapon(), and memorial_logger::write().

◆ corpse

◆ corpse_name

std::string item::corpse_name
private

Definition at line 2183 of file item.h.

Referenced by get_corpse_name(), io(), and type_name().

◆ craft_data_

◆ curammo

const itype* item::curammo = nullptr
private

Definition at line 2180 of file item.h.

Referenced by ammo_consume(), ammo_data(), ammo_set(), ammo_unset(), gun_info(), io(), and reload().

◆ damage_

int item::damage_ = 0
private

Definition at line 2242 of file item.h.

Referenced by basic_info(), damage(), damage_level(), io(), mod_damage(), on_damage(), set_damage(), and stacks_with().

◆ drop_token

pimpl<item_drop_token> item::drop_token

Two items are dropped in same "batch" if they have identical drop tokens Ideally, this would be stored outside item class.

Definition at line 2260 of file item.h.

Referenced by pickup::obtain_and_tokenize_items(), and pickup::optimize_pickup().

◆ encumbrance_update_

bool item::encumbrance_update_ = false

Definition at line 2225 of file item.h.

Referenced by on_contents_changed().

◆ energy

units::energy item::energy

Definition at line 2210 of file item.h.

Referenced by energy_remaining(), io(), mod_energy(), and process_tool().

◆ faults

◆ frequency

int item::frequency = 0

Definition at line 2215 of file item.h.

Referenced by io(), and iuse::radio_on().

◆ INFINITE_CHARGES

◆ invlet

◆ irradiation

int item::irradiation = 0

Definition at line 2217 of file item.h.

Referenced by armor_fit_info(), and io().

◆ is_favorite

◆ item_counter

◆ item_tags

◆ item_vars

std::map<std::string, std::string> item::item_vars
private

◆ last_rot_check

time_point item::last_rot_check = calendar::turn_zero
private

Time when the rot calculation was last performed.

Definition at line 2235 of file item.h.

Referenced by basic_info(), calc_rot(), io(), item(), legacy_fast_forward_time(), mod_last_rot_check(), process(), process_rot(), and set_relative_rot().

◆ light

light_emission item::light = nolight
private

Definition at line 2243 of file item.h.

Referenced by getlight(), io(), and is_emissive().

◆ mission_id

int item::mission_id = -1

◆ old_owner

faction_id item::old_owner = faction_id::NULL_ID()
mutableprivate

◆ owner

◆ player_id

int item::player_id = -1

Definition at line 2220 of file item.h.

Referenced by mission::deserialize(), io(), and mission::serialize().

◆ poison

◆ recipe_charges

int item::recipe_charges = 1

Definition at line 2212 of file item.h.

Referenced by complete_craft(), Character::compute_effective_nutrients(), and io().

◆ relic_data

◆ rot

time_duration item::rot = 0_turns
private

Accumulated rot, expressed as time the item has been in standard temperature.

It is compared to shelf life (islot_comestible::spoils) to decide if the item is rotten.

Definition at line 2233 of file item.h.

Referenced by basic_info(), minimum_freshness_duration(), spoilage_sort_order(), and stacks_with().

◆ snip_id

snippet_id item::snip_id = snippet_id::NULL_ID()

Definition at line 2216 of file item.h.

Referenced by basic_info(), io(), item(), and set_snippet().

◆ techniques

std::set<matec_id> item::techniques
private

Definition at line 2184 of file item.h.

Referenced by add_technique(), combat_info(), get_techniques(), has_technique(), io(), and stacks_with().

◆ type

const itype* item::type

Definition at line 2170 of file item.h.

Referenced by activate(), npc::activate_item(), actualize_rot(), game::add_artifact_dreams(), map::add_item(), add_monsters(), iuse::adrenaline_injector(), alcohol(), ammo_capacity(), ammo_data(), ammo_default(), ammo_effects(), ammo_required(), ammo_set(), ammo_type(), ammo_types(), iuse::antiasthmatic(), iuse::antibiotic(), iuse::anticonvulsant(), iuse::antifungal(), iuse::antiparasitic(), apply_lock_picking_tool(), armor_info(), armor_protection_info(), iuse::artifact(), iexamine::autodoc(), base_damage_thrown(), base_volume(), basic_info(), battery_info(), iuse::bell(), bionic_info(), talk_function::bionic_install(), iuse::blech(), iuse::blech_because_unclean(), iuse::blood_draw(), iuse::boltcutters(), book_info(), brewing_results(), brewing_time(), mdeath::broken(), burn(), Character::burn_fuel(), iuse::c4(), character_effects::calc_focus_equilibrium(), iuse::call_of_tindalos(), iuse::camera(), item_funcs::can_be_unloaded(), can_contain(), can_do_activity_there(), Character::can_eat(), iuse::can_goo(), can_holster(), npc::can_read(), Character::can_reload(), bandolier_actor::can_store(), fireweapon_off_actor::can_use(), manualnoise_actor::can_use(), install_bionic_actor::can_use(), saw_barrel_actor::can_use_on(), saw_stock_actor::can_use_on(), iuse::capture_monster_act(), charges_per_volume(), check_art_charge_req(), iuse::chew(), iuse::chop_logs(), chop_plank_activity(), iuse::chop_tree(), chop_tree_activity(), iuse::clear_rubble(), color(), color_in_inventory(), combat_info(), common_ammo_default(), prepared_item_consumption::consume(), Character::consume_effects(), Character::consume_med(), iuse::contacts(), contain_monster(), container_info(), convert(), count_by_charges(), activity_handlers::cracking_do_turn(), Character::crit_chance(), iuse::crowbar(), damage_melee(), iuse::datura(), deactivate(), deserialize(), mission::deserialize(), player_morale::morale_point::deserialize(), addiction::deserialize(), vehicle::deserialize(), detonate(), iuse::dig(), iuse::dig_channel(), iuse::directional_antenna(), iuse::directional_hologram(), display_name(), iuse::dive_tank(), avatar::do_read(), iuse::dog_whistle(), game::dump_stats(), Character::eat(), mattack::eat_food(), iuse::ecig(), iuse::ehandcuffs(), iuse::einktabletpc(), emit_radio_signal(), engine_displacement(), Character::enumerate_unmet_requirements(), iuse::extinguisher(), iuse::eyedrops(), faults_potential(), talk_function::field_harvest(), iuse::fill_pit(), final_info(), find_armor_data(), find_best_lock_picking_tool(), npc::find_dangerous_explosives(), npc::finish_read(), heal_actor::finish_using(), avatar_action::fire_wielded_weapon(), iuse::firecracker(), iexamine::fireplace(), iuse::flumed(), iuse::flusleep(), iuse::foodperson(), fuel_energy(), fuel_pump_terrain(), iuse::fungicide(), iuse::gasmask(), iuse::geiger(), json_talk_topic::gen_responses(), Character::get_acquirable_energy(), activatable_inventory_preset::get_action_name(), bionic_install_preset::get_anesth_amount(), bionic_uninstall_preset::get_anesth_amount(), get_available_recipes(), get_base_env_resist(), get_base_env_resist_w_filter(), read_inventory_preset::get_book(), character_funcs::get_book_fun_for(), avatar::get_book_reader(), get_category(), get_chapters(), get_clothing_mod_val(), get_comestible(), get_comestible_fun(), get_container_capacity(), activatable_inventory_preset::get_denial(), read_inventory_preset::get_denial(), bionic_install_preset::get_denial(), bionic_install_surgeon_preset::get_denial(), bionic_uninstall_preset::get_denial(), comestible_inventory_preset::get_edible_comestible(), get_encumber_when_containing(), get_env_resist(), bionic_install_preset::get_failure_chance(), bionic_install_surgeon_preset::get_failure_chance(), bionic_uninstall_preset::get_failure_chance(), ranged::get_fastest_sight(), get_gun_ups_drain(), npc::get_healing_item(), Character::get_hit_weapon(), get_layer(), get_min_str(), get_mod_locations(), ranged::get_most_accurate_sight(), zone_manager::get_near_zone_type_for_item(), bionic_install_preset::get_operation_duration(), bionic_install_surgeon_preset::get_operation_duration(), bionic_uninstall_preset::get_operation_duration(), comestible_inventory_preset::get_order(), get_pet_armor_bodytype(), get_pet_armor_max_vol(), get_pet_armor_min_vol(), get_plant_epoch(), get_plant_name(), get_property_int64_t(), get_property_string(), get_qualities(), get_quality(), get_reload_time(), get_remaining_capacity_for_liquid(), get_storage(), get_techniques(), get_thickness(), get_total_capacity(), get_use_internal(), plot_options::get_zone_name_suggestion(), getGasDiscountCardQuality(), getlight_emit(), goes_bad_after_opening(), iuse::granade(), iuse::granade_act(), gun_damage(), gun_dispersion(), gun_info(), gun_noise(), gun_range(), gun_recoil(), gun_recoil_multiplier(), iuse::gun_repair(), gun_skill(), npc_ai::gun_value(), gunmod_info(), avatar_funcs::gunmod_installation_odds(), iuse::hacksaw(), iuse::hairkit(), iuse::hammer(), iuse::handle_ground_graffiti(), ranged::handle_gun_damage(), has_effect_when_carried(), has_effect_when_wielded(), has_effect_when_worn(), has_explosion_data(), has_flag(), npc::has_healing_options(), has_property(), has_technique(), has_use(), npc::heal_player(), npc::heal_self(), iuse::honeycomb(), in_its_container(), countdown_actor::info(), info(), iuse::inhaler(), inherit_flags(), Character::invoke_item(), avatar::invoke_item(), npc::invoke_item(), io(), is_ammo(), is_artifact(), is_bandolier(), is_battery(), is_bionic(), is_book(), is_brewable(), is_bucket(), is_container(), is_deployable(), is_emissive(), is_engine(), is_fuel(), is_gun(), is_gunmod(), is_holster(), is_magazine(), is_non_resealable_container(), is_null(), avatar_funcs::is_pet_food(), is_seed(), activatable_inventory_preset::is_shown(), is_tool(), is_toolmod(), is_transformable(), is_upgrade(), is_watertight_container(), is_wheel(), item(), item_has_uses_recursive(), Character::item_reload_cost(), item_reload_option::item_reload_option(), iuse::jackhammer(), iuse::jet_injector(), submap::load(), iuse::lumber(), iuse::ma_manual(), made_of(), magazine_compatible(), magazine_default(), magazine_info(), magazine_integral(), iuse::makemound(), mark_chapter_as_read(), iuse::marloss(), iuse::marloss_gel(), iuse::marloss_seed(), max_damage(), iuse::meditate(), Character::meets_requirements(), Character::meets_stat_requirements(), iuse::melatonin_tablet(), npc_ai::melee_value(), iuse::meth(), mill_load_food(), min_damage(), iuse::mind_splicer(), mine_activity(), minimum_freshness_duration(), iuse::mininuke(), mod_damage(), mod_energy(), Item_modifier::modify(), iuse::modify_grid_connections(), Character::modify_morale(), iuse::mop(), avatar_action::move(), iuse::mp3(), iuse::mp3_on(), iuse::multicooker(), mutagen_common_checks(), iuse::mycus(), iuse::noise_emitter_off(), iuse::noise_emitter_on(), on_contents_changed(), on_drop(), on_pickup(), on_takeoff(), on_wear(), on_wield(), operator<(), iuse::oxygen_bottle(), iuse::pheromone(), iuse::plantblech(), iuse::poison(), iuse::portal(), Character::pour_into(), price(), process(), game::process_artifact(), process_cable(), process_extinguish(), process_internal(), Character::process_items(), process_tool(), process_vehicle_items(), process_wet(), vehicle_part::properties_to_item(), iuse::prozac(), iuse::purifier(), iuse::purify_iv(), iuse::purify_smart(), item_reload_option::qty(), qualities_info(), quality_of(), plot_options::query_seed(), iuse::radglove(), iuse::radio_off(), iuse::radio_on(), iuse::radiocar(), iuse::radiocaron(), iuse::radiocontrol(), examine_item_menu::rate_action_use(), rate_food(), read(), avatar::read(), read_inventory_preset::read_inventory_preset(), avatar_action::reload(), reload(), activity_handlers::reload_finish(), iuse::remoteveh(), repair_item_actor::repair_recipe_difficulty(), repaired_with(), reset_cable(), mattack::riotbot(), iuse::rm13armor_off(), iuse::rm13armor_on(), iuse::robotcontrol(), iexamine::safe(), iuse::seed(), mission::serialize(), player_morale::morale_point::serialize(), addiction::serialize(), vehicle::serialize(), iuse::sewage(), iuse::shavekit(), activity_handlers::shear_finish(), iuse::shocktonfa_off(), sight_dispersion(), simulate_burn(), iuse::siphon(), skim_book_msg(), iuse::sleep(), smoker_activate(), iuse::smoking(), activity_handlers::spellcasting_finish(), spoilage_sort_order(), stacks_with(), activity_handlers::start_fire_do_turn(), activity_handlers::start_fire_finish(), npc::start_read(), iuse::stimpack(), iuse::strong_antibiotic(), symbol(), iuse::talking_doll(), iuse::tazer(), iuse::teleport(), iuse::thorazine(), ranged::throw_item(), ranged::time_to_attack(), npc::time_to_read(), avatar::time_to_read(), tname(), iuse::toolmod_attach(), toolweapon_off(), toolweapon_on(), iuse::towel_common(), try_consume(), type_name(), typeId(), avatar_funcs::unload_item(), target_ui::update_ammo_range_from_gun_mode(), update_clothing_mod_val(), charger_tile::update_internal(), iuse_transform::use(), countdown_actor::use(), consume_drug_iuse::use(), pick_lock_actor::use(), firestarter_actor::use(), fireweapon_off_actor::use(), fireweapon_on_actor::use(), manualnoise_actor::use(), heal_actor::use(), mutagen_actor::use(), mutagen_iv_actor::use(), install_bionic_actor::use(), avatar_funcs::use_item(), vehicle::use_monster_capture(), iuse::vaccine(), npc::value(), iuse::vibe(), volume(), iuse::vortex(), iuse::weak_antibiotic(), npc_ai::weapon_value(), iuse::weed_cake(), weight(), wheel_area(), vehicle_part::wheel_diameter(), vehicle_part::wheel_width(), npc::wield_better_weapon(), npc_ai::wielded_value(), npc::will_accept_from_player(), will_explode_in_fire(), and iuse::xanax().


The documentation for this class was generated from the following files: